Vicennial's blog

By Vicennial, history, 8 years ago, In English

86D - Мощный массив

I tried implementing Mo's Algorithm to solve this problem but I ran into a couple of TLE's when taking block size as sqrt(Max N) which is 448.
The submission can be viewed here-21756475 The result was TLE when using block size=448.
In the next submission-21756591 , I put block size=1000 and the result was AC.

So my question is how do I figure out what value to use as my block size?

  • Vote: I like it
  • 0
  • Vote: I do not like it

»
8 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by Vicennial (previous revision, new revision, compare).

»
8 years ago, # |
  Vote: I like it +1 Vote: I do not like it

Assuming you do not want to submit a large number of times with different block sizes, one way to do this is by creating a test case with the highest possible values for n and t (and randomly generated queries) and testing the runtimes for different block sizes.

»
8 years ago, # |
  Vote: I like it +3 Vote: I do not like it

I submitted different forms of my code for around 20 times in this question. What I saw is that time taken in this question changes abruptly even on subtle changes in code.

For example I changed ll to int in your code for some arrays and numbers except answer ones http://codeforces.me/contest/86/submission/24079499 and it got AC.

When I was doing it, I removed #include <bits/stdc++.h> from my code and time reduced to 2240 from 3630 ms. I think it takes pretty neat and to the point code at Codeforces otherwise these things shouldn't matter.