Problem — 1539C
My O(N*log(N)) PyPy3 code got TLE verdict for N — 2e5 (worst case)
Can someone explain what operations are being heavy in my code? and how can I optimize them?
Here is the submission link — submission
№ | Пользователь | Рейтинг |
---|---|---|
1 | ecnerwala | 3649 |
2 | Benq | 3581 |
3 | orzdevinwang | 3570 |
4 | Geothermal | 3569 |
4 | cnnfls_csy | 3569 |
6 | tourist | 3565 |
7 | maroonrk | 3531 |
8 | Radewoosh | 3521 |
9 | Um_nik | 3482 |
10 | jiangly | 3468 |
Страны | Города | Организации | Всё → |
№ | Пользователь | Вклад |
---|---|---|
1 | maomao90 | 174 |
2 | awoo | 164 |
3 | adamant | 161 |
4 | TheScrasse | 159 |
5 | nor | 158 |
6 | maroonrk | 156 |
7 | -is-this-fft- | 152 |
8 | SecondThread | 147 |
9 | orz | 146 |
10 | pajenegod | 145 |
Problem — 1539C
My O(N*log(N)) PyPy3 code got TLE verdict for N — 2e5 (worst case)
Can someone explain what operations are being heavy in my code? and how can I optimize them?
Here is the submission link — submission
Название |
---|
Who the fck said you to use pypy...use c++ and you're never gonna get these types of complaints.
Switch to c++ and thank me latter.
Why don't you comment with your real account?
:)
Same thing happened with me ..when I used python it gave me accepted..but for pypy tle...why are these problems with python and pypy...
Specific in this case pure Python is faster, but idk how to explain it
could you explain...how to know when to use python and when pypy..
Might be due to 64 bit integers. pajenegod has written about it. https://codeforces.com/blog/entry/90184
Please update PyPy3 :D
Yep, 64 bit PyPy would have ran super fast.
One problem is that in pypy3 it's faster to read as bytes instead of string. If you replace
input = sys.stdin.readline
withinput = sys.stdin.buffer.readline
it should pass. Another alternative is to read the entire file with a singleos.read()
orsys.stdin.buffer.read()
at the beginning with something likeinput = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
. Or just use the fast i/o template from pyrival: https://github.com/cheran-senthil/PyRival/blob/master/templates/template.pyBut the other problem is that integers larger than 32 bits will switch to a slow big integer implementation and sorting that is slow. I don't know of any good solution for that right now (EDIT: apparently pyrival has an long_ordersort, pajenegod orz!!!). It might get better if we get an option to submit in 64bit pypy in the future (see pajenegod's post: https://codeforces.com/blog/entry/90184)
EDIT2: I tried out the long_ordersort implementation from pyrival (it needed one bug fix to work in pypy3) and it was around 650ms: 120134673. I noticed some submissions which were faster by casting to floats, but that trick only works up to around 2**53 so they are hackable: 120130807
"If you replace input = sys.stdin.readline with input = sys.stdin.buffer.readline" — It worked, thanks.
Edit: Will use long_ordersort for sorting 64-bit integers in future submissions. 120138937