BZOJ3809 Gty's two-cornered sister sequence

Source: Internet
Author: User

Finally did the BZ on the latest topic 2333

The question is ... Team, then query the tree-like array.

The result t, eh eh eh eh%>_<%, how can this!

Another way to find him: Hzwer's Pieces

NN, is to divide the color into n blocks, then the word modified O (1), the word query O (n/sz + 2 * sz)

SZ = sqrt (N/2) is best (theoretically), actually SZ = sqrt (n) is not slow at all .... do you want to try Sz = log (n) next time ?

1 /**************************************************************2 problem:38093 User:rausen4 language:c++5 result:accepted6 time:26248 Ms7 memory:25428 KB8 ****************************************************************/9  Ten#include <cstdio> One#include <cmath> A#include <algorithm> -   - using namespacestd; the Const intN =100005; - Const intM =1000005; - Const intSqrt_n = -; -   + intN, Q, sz; - intA[n]; + intB[sqrt_n], w[n], cnt[n]; A intAns[m]; at   - structData { -     intL, R, a, B, W; -       -InlineBOOL operator< (ConstData &x)Const { -         returnW[l] = = W[x.l]? R < X.r:w[l] <W[X.L]; in     } - } Q[m]; to   +InlineintRead () { -     intx =0; the     CharCH =GetChar (); *      while(Ch <'0'||'9'<ch) $CH =GetChar ();Panax Notoginseng      while('0'<= CH && Ch <='9') { -x = x *Ten+ CH-'0'; theCH =GetChar (); +     } A     returnx; the } +   - intQueryintXinty) { $     intres =0, I; $     if(W[x] = =W[y]) { -          for(i = x; i <= y; + +)i) -             if(Cnt[i]) + +Res; the}Else { -          for(i = w[x] +1; i < w[y]; ++i)WuyiRes + =B[i]; the          for(i = w[x] * SZ; i >= x;--i) -             if(Cnt[i]) + +Res; Wu          for(i = (W[y]-1) * sz +1; I <= y; ++i) -             if(Cnt[i]) + +Res; About     } $     returnRes; - } -   -InlinevoidAddintCintdel) { A     if(!cnt[c]) + +B[w[c]]; +CNT[C] + =del; the     if(!cnt[c])--B[w[c]]; - } $   the intMain () { the     intI, L, R; then = Read (), Q = Read (), Sz = (int) sqrt (N/2); the      for(i =1; I <= N; ++i) -A[i] = Read (), w[i] = (int) (I-1)/sz +1; in      for(i =1; I <= Q; ++i) { theQ[I].L = Read (), Q[I].R = Read (), q[i].a = Read (), q[i].b =read (); theQ[i]. W =i; About     } theSort (q +1, q + q +1); the       the      for(i = L =1, r =0; I <= Q; ++i) { +          for(; l < Q[I].L;) Add (a[l++],-1); -          for(; l > q[i].l;) Add (A[--l],1); the          for(; R < Q[I].R;) Add (A[++r],1);Bayi          for(; r > q[i].r;) Add (a[r--],-1); theAns[q[i]. W] =query (Q[I].A, q[i].b); the     } -      for(i =1; I <= Q; ++i) -printf"%d\n", Ans[i]); the     return 0; the}
View Code

(P.S. Rank 2 is good, Orz rank 1 is not the MO team . )

[Email protected] 2014/12/21 23:13

Wow, rank 1 god Ben wangyisong1996 take the initiative to find Konjac Konjac play ~ very happy AH

God Ben said he used the card! Often! Number! Mo Team, time unexpectedly only half, simply to kneel >_<

Another: Sz = log (n) is dead, T is miserable

Why write output optimization instead of slower = = unscientific

BZOJ3809 Gty's two-cornered sister sequence

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.