Bzoj 3809 MO Team

Source: Internet
Author: User

Harvest:

1, by the way when the block record each location belongs to the block, and then once the order is OK.

2, to weigh between the "interval move" and "Query results" time, MO team algorithm general interval moving frequency is much larger than the query results, so we choose the auxiliary data structure to pay attention to, I began to write is the range segment tree, the limit of their own data to 1m8s, change into a tree array to 24s, or not , hzwer as long as 13s, a closer look at Hzwer code, found TA with a sub-block, O (1) Modify O (n0.5) query, after changing the composition block is indeed much faster.

3, the size of the block theory of the optimal value is O (n*m-0.5), the first set into this turn 35 card, changed into Hzwer N/2 after 29s, so do the problem to try it yourself.

1 /**************************************************************2 problem:38093 user:idy0024 language:c++5 result:accepted6 time:29336 Ms7 memory:26988 KB8 ****************************************************************/9  Ten#include <cstdio> One#include <cctype> A#include <cstring> -#include <cmath> -#include <algorithm> the #defineMAXN 100010 - #defineMAXM 1000010 - #defineLowbit (i) ((i) & (-(i))) - using namespacestd; +   -   + intN, M; A intLX[MAXN], RX[MAXN], MCCNO[MAXN], Stot; at intW[MAXN]; - intANS[MAXM]; - intCNT[MAXN], SIZ[MAXN], CMC[MAXN]; -   -   - structQu { in     intL, R, a, B, id; -     BOOL operator< (ConstQu & C)Const { to         returnMCCNO[L]&LT;MCCNO[C.L] | | (MCCNO[L]==MCCNO[C.L] && r<C.R); +     } - }; the Qu QU[MAXM]; *   $ voidAddintPOS) {Panax Notoginsengsiz[pos]++; -     if(siz[pos]==1) cmc[mccno[pos]]++; the } + voidDelintPOS) { Asiz[pos]--; the     if(siz[pos]==0) cmc[mccno[pos]]--; + } - intQueryintLintr) { $     intLM = Mccno[l], RM =Mccno[r]; $     intRT =0; -     if(lm==RM) { -          for(intJ=l; j<=r; J + + ) the             if(Siz[j]) rt++; -         returnRT;Wuyi     } the      for(intb=lm+1; b<rm; b++ ) -RT + =Cmc[b]; Wu      for(intJ=l; j<=rx[lm]; J + + ) -         if(Siz[j]) rt++; About      for(intJ=LX[RM]; j<=r; J + + ) $         if(Siz[j]) rt++; -     returnRT; - } - voidpartition () { A     intLen = (int) Ceil (sqrt (n/2)+1); +Stot = n/Len; therx[0] =0; -      for(intI=1; i<=stot; i++ ) { $Lx[i] = rx[i-1]+1; theRx[i] = rx[i-1]+Len; the     } the     if(rx[stot]!=N) { thestot++; -Lx[stot] = rx[stot-1]+1; inRx[stot] =N; the     } the      for(intI=1; i<=stot; i++ )  About          for(intJ=lx[i]; j<=rx[i]; J + + ) theMCCNO[J] =i; the } the voidWork () { +Sort (qu+1, qu+1+m); -   the     intLF = qu[1].L;Bayi     intRG = qu[1].R; the      for(intJ=LF; j<=rg; J + + ) the Add (W[j]); -ans[qu[1].id] = query (qu[1].A, qu[1].b); -      for(intq=2; q<=m; q++ ) { the          while(QU[Q].L&LT;LF) Add (w[--LF]); the          while(QU[Q].L&GT;LF) del (w[lf++]); the          while(QU[Q].R&GT;RG) Add (w[++RG]); the          while(QU[Q].R&LT;RG) del (w[rg--]); -Ans[qu[q].id] =query (QU[Q].A, qu[q].b); the     } the } the intMain () {94scanf"%d%d", &n, &m); the      for(intI=1; i<=n; i++ ) thescanf"%d", w+i); the      for(intI=1; i<=m; i++ ) {98scanf"%d%d%d%d", &AMP;QU[I].L, &AMP;QU[I].R, &AMP;QU[I].A, &qu[i].b); AboutQu[i].id =i; -     }101 partition ();102 Work ();103      for(intI=1; i<=m; i++ ) 104printf"%d\n", Ans[i]); the}
View Code

Bzoj 3809 MO Team

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.