Блог пользователя harsh-apcr

Автор harsh-apcr, история, 2 года назад, По-английски

Submission : https://mirror.codeforces.com/contest/1878/submission/252116337

I am new to python so I was practicing it on codeforces problems, the submission I referenced above is exceeding memory limits for very small values of $$$n$$$.

I think you don't need to really understand the problem statement, I suspect the problem is in implementation of segment tree. (as the solve() function really only has binary search which is implemented iteratively)

Any help will be appreciated

here is the code :

Spoiler
  • Проголосовать: нравится
  • 0
  • Проголосовать: не нравится

»
2 года назад, скрыть # |
Rev. 3  
Проголосовать: нравится +1 Проголосовать: не нравится

Interesting, it's something with pypy and sys.setrecursionlimit(...). If you make it smaller it will be fine. Though with standart python the memory is fine

Anyways, recursion in python is really bad, so it's better to replace it with a stack. Here you can check out a simple decorator for that

*Actually, you don't even need it because your recursion depth is very small and you can just remove setrecursionlimit