Can anyone check my solution Id. 34415408. I don't know why it is giving TLE. Code link : http://mirror.codeforces.com/contest/86/submission/34415408
# | User | Rating |
---|---|---|
1 | tourist | 3993 |
2 | jiangly | 3743 |
3 | orzdevinwang | 3707 |
4 | Radewoosh | 3627 |
5 | jqdai0815 | 3620 |
6 | Benq | 3564 |
7 | Kevin114514 | 3443 |
8 | ksun48 | 3434 |
9 | Rewinding | 3397 |
10 | Um_nik | 3396 |
# | User | Contrib. |
---|---|---|
1 | cry | 167 |
2 | Um_nik | 163 |
3 | maomao90 | 162 |
3 | atcoder_official | 162 |
5 | adamant | 159 |
6 | -is-this-fft- | 158 |
7 | awoo | 157 |
8 | TheScrasse | 154 |
9 | Dominater069 | 153 |
9 | nor | 153 |
Can anyone check my solution Id. 34415408. I don't know why it is giving TLE. Code link : http://mirror.codeforces.com/contest/86/submission/34415408
Name |
---|
Auto comment: topic has been updated by ryuga222 (previous revision, new revision, compare).
First of all notice that this is an old problem. So your execution time will be multiplied by 2.
There are many optimizations that you can do —
scanf/printf
for IO.long long
variables, it takes too much time. Use only when necessary.long long BLOCK = 512
, if you useconst long long
compiler will optimize division / modulo for with the number.cnt[]
array 5 times inadd/remove
function. But it is possible to design those by accessing only twice or even once.i++
, and changing it to++i
doesn't affect much. Then use++i
. Somehow++i
is more faster.So, it is reasonable that you got TLE.
damn... it worked when i optimized the add/remove function. Can't believe it was giving TLE. Thanks a lot :D.
how i can pre-calculate the BLOCK in main function?? i don't understand that.
Take another array
blc[]
, and precalculate likeblc[i] = i / block_size;
, then use this array in compare function.