51nod1485 alphabetical order

Source: Internet
Author: User

Exercises

Open 26 segment number, record the number of occurrences of each letter in the interval, modify the interval is set to a number of operations can be. There is also a balance tree to do

1#include <cstdio>2#include <algorithm>3#include <cstring>4 #defineLL Long Long5 #defineRG Register6 #defineN 2000107 #defineLS (u<<1)8 #defineRS (u<<1|1)9 #defineMid ((A[U].L+A[U].R) >>1)Ten using namespacestd; One intn,m,opt,l,r,q[ -]; A structtree{ -     intl,r,cnt[ -],Set; -}a[n<<2]; theInlineintRead () { -     intk=0, f=1;CharC=GetChar (); -      while(c<'0'|| C>'9') c=='-'&& (f=-1), c=GetChar (); -      while('0'<=c&&c<='9') k=k*Ten+c-'0', c=GetChar (); +     returnk*F; - } + voidBuildintUintLintR) { AA[u].l=l; A[u].r=r; A[u].Set=-1; at     if(l<R) { -Build (Ls,l,mid); Build (rs,mid+1, R); -          for(RGintI=0;i< -; i++) a[u].cnt[i]=a[ls].cnt[i]+A[rs].cnt[i]; -     } -     ElseA[u].cnt[getchar ()-'a']++; - } inInlinevoidPushdown (intu) { -     if(A[u].Set==-1)return;int Set=a[u].Set; to      for(RGintI=0;i< -; i++) a[ls].cnt[i]=a[rs].cnt[i]=0; +A[ls].cnt[a[ls].Set=Set]= (a[ls].r-a[ls].l+1); -A[RS].CNT[A[RS].Set=Set]= (a[rs].r-a[rs].l+1); theA[u].Set=-1; * } $ voidUpdateintUintLintRint Set){Panax Notoginseng     if(l<=a[u].l&&a[u].r<=R) { -          for(RGintI=0;i< -; i++) a[u].cnt[i]=0; theA[u].cnt[a[u].Set=Set]= (a[u].r-a[u].l+1); +         return; A     } the pushdown (u); +     if(l<=mid) Update (LS,L,R,Set); -     if(r>mid) Update (RS,L,R,Set); $      for(RGintI=0;i< -; i++) a[u].cnt[i]=a[ls].cnt[i]+A[rs].cnt[i]; $ } - voidQueryintUintLintR) { -     if(l<=a[u].l&&a[u].r<=R) { the          for(RGintI=0;i< -; i++) q[i]+=A[u].cnt[i]; -         return;Wuyi     } the pushdown (u); -     if(l<=mid) query (LS,L,R); Wu     if(r>mid) query (RS,L,R); - } About void  out(intUintPOS) { $     if(A[U].L==A[U].R) for(RGintI=0;i< -; i++)if(A[u].cnt[i]) {Putchar (i+'a');return;} - pushdown (u); -     if(Pos<=mid) out(Ls,pos);Else  out(Rs,pos); - } A intMain () { +N=read ();    M=read (); Build1,1, n); the      while(m--){ -memset (Q,0,sizeof(q)); $L=read (); R=read (); opt=read (); theQuery1, l,r);intnow=l; the         if(opt==1){ the              for(RGintI=0;i< -; i++)if(Q[i]) update (1, now,now+q[i]-1, i), now+=Q[i]; the         } -         Else{ in              for(RGintI= -; i>=0; i--)if(Q[i]) update (1, now,now+q[i]-1, i), now+=Q[i]; the         } thememset (Q,0,sizeof(q)); About     } the      for(RGintI=1; i<=n;i++) out(1, i); the     return 0; the}
View Code

Method.

51nod1485 alphabetical order

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.