### ryuga222's blog

By ryuga222, history, 7 months ago, ,

Can anyone check my solution Id. 34415408. I don't know why it is giving TLE. Code link : http://codeforces.com/contest/86/submission/34415408

•
• -8
•

 » 7 months ago, # |   0 Auto comment: topic has been updated by ryuga222 (previous revision, new revision, compare).
 » 7 months ago, # |   +16 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 — Honestly use scanf/printf for IO. You are using too much long long variables, it takes too much time. Use only when necessary. You are using long long BLOCK = 512, if you use const long long compiler will optimize division / modulo for with the number. In the compare function, you are calculating the block number there, again and again. The division is a costly operator. You can pre-calculate the block number in main function and just use that. You are accessing the cnt[] array 5 times in add/remove function. But it is possible to design those by accessing only twice or even once. Silly optimization — if anywhere you have 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.
•  » » 7 months ago, # ^ |   +5 damn... it worked when i optimized the add/remove function. Can't believe it was giving TLE. Thanks a lot :D.
•  » » » 3 months ago, # ^ |   0 where you change add/remove function?
•  » » 3 months ago, # ^ |   0 how i can pre-calculate the BLOCK in main function?? i don't understand that.
•  » » » 3 months ago, # ^ |   0 Take another array blc[], and precalculate like blc[i] = i / block_size;, then use this array in compare function.