Submission : https://codeforces.me/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
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 fineAnyways, 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
thanks, this issue is resolved, but apparently it got TLE
submission : https://codeforces.me/contest/1878/submission/252135902
The same code in C++ would've passed very easily, what I am doing wrong ? Is it due to python lists ? should I be using numpy arrays or is there some other fault
I'd say, it is just due to python speed :p
I could reach TL10 (for example https://codeforces.me/contest/1878/submission/252137501) but i don't really know what to improve except changing the algo
Maybe you can look through status page for some solution with the same idea that has passed in python
For example there are some solves with segment tree from below, but maybe there are with standart too
From Differences between PyPy and CPython:
So calling
setrecursionlimit
means that it tries to allocate enough memory for the call stack to perform recursions of approximatelyn
in depth.