求问为什么,在持久时,没有更改儿子????

回复帖子

@JK_LOVER 2020-08-01 22:02 回复
#include<bits/stdc++.h>
using namespace std;
const int N = 100100;
int read(){
    int x;scanf("%d",&x);return x;
}
int lc[N],rc[N],top[N],rt[N],val[N],n,size = 0;
int update(int u,int l,int r,int pos,int key)
{
    int p = ++size;
    lc[p] = lc[u];rc[p] = rc[u];
    if(l == r) {val[p] = key;return p;}
    int mid = l + r >> 1;
    if(pos <= mid) lc[p] = update(lc[u],l,mid,pos,key);
    else rc[p] = update(rc[u],mid+1,r,pos,key);
    return p;
}
int ask(int u,int l,int r,int pos)
{
    if(l == r) {return val[u];}
    int mid = l + r >> 1;
    if(pos <= mid) return ask(lc[u],l,mid,pos);
    else return ask(rc[u],mid+1,r,pos);
}
int main()
{
    n = read();
    for(int i = 1;i <= n;i++)
    {
        char ch[5];
        scanf("%s",ch);

        if(ch[0] == 'a')
        {
            int x = read();
            top[i] = top[i-1] + 1;
            rt[i] = update(rt[i-1],1,top[i],top[i],x);
        }
        if(ch[0] == 's')
        {   
            top[i] = top[i-1];
            rt[i] = rt[i-1];
//          cout<<"top[i] "<<top[i]<<endl;
            rt[i] = update(rt[i-1],1,top[i],top[i],0);
            top[i]--;

        }
        if(ch[0] == 't')
        {
            int x = read();
            rt[i] = rt[x-1];top[i] = top[x-1];
        }
        printf("%d\n",top[i] == 0?-1:ask(rt[i],1,top[i],top[i]));
        for(int j = 1;j <= top[i];j++)
        {
        cout<<"j:: "<<j<<" "<<ask(rt[i],1,top[i],j)<<endl;
        }
    }
}
反馈
如果你认为某个帖子有问题,欢迎向洛谷反馈,以帮助更多的同学。



请具体说明理由,以增加反馈的可信度。