We just have to force the size of the enumeration block ...
The total complexity of the enumeration is O (N/1 + n/2 + n/3 + ...) = O (n * logn)
How to go heavy ... Direct brute force hash and throw it into set, total complexity O (n * log2n)
1 /**************************************************************2 problem:20813 User:rausen4 language:c++5 result:accepted6 time:4932 Ms7 memory:18312 KB8 ****************************************************************/9 Ten#include <cstdio> One#include <algorithm> A#include <Set> -#include <vector> - the using namespacestd; -typedef unsignedLong Longull; - Const intN = 5e5 +5; - Const int Base=200191; + - intN, A[n], ans; + ull b[n], h1[n], h2[n]; AVector <int>Ans; atVector <int>:: iterator it; - -InlineintRead () { - intx =0, SGN =1; - CharCH =GetChar (); - while(Ch <'0'||'9'<ch) { in if(ch = ='-') SGN =-1; -CH =GetChar (); to } + while('0'<= CH && Ch <='9') { -x = x *Ten+ CH-'0'; theCH =GetChar (); * } $ returnSGN *x;Panax Notoginseng } - theUll Calc1 (intLintr) { + returnH1[R]-H1[l-1] * b[r-l +1]; A } the +Ull CALC2 (intLintr) { - returnH2[L]-h2[r +1] * b[r-l +1]; $ } $ - Set<ull>S; - intCalcintSZ) { the s.clear (); - for(inti =1; i + SZ-1<= N; i + =sz)WuyiS.insert (min (Calc1 (i, i + sz-1), CALC2 (i, i + sz-1))); the return(int) s.size (); - } Wu - intMain () { About intI, t; $n =read (); - for(i =1; I <= N; ++i) A[i] =read (); - for(i = b[0] =1; I <= N; ++i) B[i] = b[i-1] *Base; - for(i =1; I <= N; ++i) AH1[i] = h1[i-1] *Base+A[i]; + for(i = n; i;--i) theH2[i] = h2[i +1] *Base+A[i]; -Ans =0; $ for(i =1; I <= N; ++i) { thet =Calc (i); the if(T >ans) { theAns =T; the ans.clear (); - } in if(ans = =t) ans.push_back (i); the } theprintf"%d%d\n", ans, (int) ans.size ()); About for(it = Ans.begin (); it! =ans.end ();) { theprintf"%d", *it), + +it; the if(It = = Ans.end ()) puts (""); the ElsePutchar (' '); + } - return 0; the}
View Code
BZOJ2081 [Poi2010]beads