标签:dig pos http www. ret == org 可持久化线段树 include
权当温习主席树模板
#include<cstdio> #include<cstdlib> #include<cctype> #define left (rt<<1) #define right (rt<<1|1) #define mid ((l+r)>>1) #define lson l,mid,left #define rson mid+1,r,right inline long long read(){ long long num=0,f=1; char ch=getchar(); while(!isdigit(ch)){ if(ch==‘-‘) f=-1; ch=getchar(); } while(isdigit(ch)){ num=num*10+ch-‘0‘; ch=getchar(); } return num*f; } int root[2000000]; int ls[2000000]; int rs[2000000]; char tree[2000000]; int len[2000000]; int ID; void add(int l,int r,int &rt,char x,int pos,int last){ rt=++ID; if(l==r){ tree[rt]=x; return; } ls[rt]=ls[last]; rs[rt]=rs[last]; if(pos<=mid) add(l,mid,ls[rt],x,pos,ls[last]); else add(mid+1,r,rs[rt],x,pos,rs[last]); } int query(int pos,int l,int r,int rt){ if(l==r) return rt; if(pos<=mid) return query(pos,l,mid,ls[rt]); else return query(pos,mid+1,r,rs[rt]); } int now; int main(){ int n=read(); for(int i=1;i<=n;++i){ char ch[10];int x; scanf("%s",ch); if(ch[0]==‘Q‘){ x=read(); int pos=query(x,1,n,root[now]); printf("%c\n",tree[pos]); } else if(ch[0]==‘U‘){ x=read(); now++; len[now]=len[now-x-1]; root[now]=root[now-x-1]; } else{ char c[10]; scanf("%s",c); now++;len[now]=len[now-1]+1; add(1,n,root[now],c[0],len[now],root[now-1]); } } return 0; }
标签:dig pos http www. ret == org 可持久化线段树 include
原文地址:http://www.cnblogs.com/cellular-automaton/p/7509828.html