Bzoj4546-codechef XRQRS (can be persisted trie)

Source: Internet
Author: User

Chinese question test instructions I won't say it.

Parsing: Can persist trie template problem, see the comment

Code

#include <cstdio>#include<cstring>#include<string>#include<algorithm>using namespacestd;Const intmaxbit= +;Const intmaxn=10500005;inttr[500002];structpertrie{intID; intnext[maxn][2],NUM[MAXN]; voidInit () {id=next[0][0]=next[0][1]=num[0]=0; }//Initialize    intFintXinti) {return(x>>i) &1; }//determine if x is 0 or 1    voidInsert (int& RT,intPreintXintPos//Insert{RT=++ID; next[rt][0]=next[pre][0];//Fu etnext[rt][1]=next[pre][1]; NUM[RT]=num[pre]+1;//Quantity plus 1        if(pos==-1)return; intD=f (x,pos); Insert (Next[rt][d],next[pre][d],x,pos-1); }    intMaxxor (intLintRintx) {intret=0;  for(inti=maxbit;i>=0; i--)        {            intD=f (x,i); inta=next[l][d^1],b=next[r][d^1]; if(num[b]-num[a]>0) ret|= (1<<i), l=a,r=b;//determine if there is            ElseL=next[l][d],r=Next[r][d]; }        returnret; }    intMinnum (intLintRintx) {intret=0;  for(inti=maxbit;i>=0; i--)        {            intD=f (x,i); if(d) ret+=num[next[r][0]]-num[next[l][0]];//It's smaller than that, plus.L=NEXT[L][D]; R=Next[r][d]; } ret+=NUM[R]-NUM[L];//<= to add it,<.        returnret; }    intKth (intLintRintk) {intret=0;  for(inti=maxbit;i>=0; i--)        {            intt=num[next[r][0]]-num[next[l][0]]; if(t>=k) l=next[l][0],r=next[r][0];//enough            ElseRet|= (1<<i), l=next[l][1],r=next[r][1],k-=T; }        returnret; }}pt;intMain () {intQ; scanf ("%d",&Q); intType,l,r,x,cnt=0; tr[0]=0;    Pt.init ();  while(q--) {scanf ("%d",&type); if(type==1) {scanf ("%d",&x); ++CNT; Pt. Insert (tr[cnt],tr[cnt-1],x,maxbit);//Insert a new value        }        Else if(type==2) {scanf ("%d%d%d",&l,&r,&x); printf ("%d\n"Pt. Maxxor (tr[l-1],TR[R],X) ^x); }        Else if(type==3) {scanf ("%d",&x); CNT-=x; }        Else if(type==4) {scanf ("%d%d%d",&l,&r,&x); printf ("%d\n"Pt. Minnum (tr[l-1],tr[r],x)); }        Else{scanf ("%d%d%d",&l,&r,&x); printf ("%d\n", Pt.kth (tr[l-1],tr[r],x)); }    }    return 0;}
View Code

Bzoj4546-codechef XRQRS (can be persisted trie)

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.