harsh-apcr's blog

By harsh-apcr, history, 2 years ago, In English

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
  • Vote: I like it
  • 0
  • Vote: I do not like it

»
2 years ago, hide # |
Rev. 3  
Vote: I like it +1 Vote: I do not like it

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