BZOJ2081 [Poi2010]beads

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.