日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 >

【Luogu】P1383高级打字机

發(fā)布時(shí)間:2024/9/5 40 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【Luogu】P1383高级打字机 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

可持久化線段樹模板題之一。

權(quán)當(dāng)溫習(xí)主席樹模板

#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,rightinline 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; }

?

轉(zhuǎn)載于:https://www.cnblogs.com/cellular-automaton/p/7509828.html

總結(jié)

以上是生活随笔為你收集整理的【Luogu】P1383高级打字机的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。