蒟蒻求助MLE
查看原帖
蒟蒻求助MLE
208776
Gavin0576楼主2020/9/9 21:00

交上去发现莫名的挂了,mle卡了好多没有卡过去,照着第一篇题解打的pup

#include<bits/stdc++.h>
using namespace std;
#define SIZE 2000010
int a[SIZE],root[SIZE];
int n,m;
int tot=0;
struct p{
    int l,r,val;
}tr[SIZE<<2];
int build(int p,int l,int r){
    p=++tot;
    if(l==r){
        tr[p].val=a[l];
        return tot;
    }
    int mid=l+r>>1;
    tr[p].l=build(tr[p].l,l,mid);
    tr[p].r=build(tr[p].r,mid+1,r);
    return p;
}
int New(int x){
    ++tot;
    tr[tot]=tr[x];
    return tot;
}
int update(int p,int l,int r,int pos,int val){
    p=New(p);
    if(l==r) tr[p].val=val;
    else{
        int mid=l+r>>1;
        if(pos<=mid) tr[p].l=update(tr[p].l,l,mid,pos,val);
        else tr[p].r=update(tr[p].r,mid+1,r,pos,val);
    }
    return p;
}
int Query(int p,int l,int r,int pos){
    if(l==r) return tr[p].val;
    else{
        int mid=l+r>>1;
        if(pos<=mid) return Query(tr[p].l,l,mid,pos);
        else return Query(tr[p].r,mid+1,r,pos);
    }
}
int main(){
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++) scanf("%d",&a[i]);
    root[0]=build(0,1,n);
    for(int i=1;i<=m;i++){
        int x,y,z,w;
        scanf("%d%d%d",&x,&y,&z);
        if(y==1){
            scanf("%d",&w);
            root[i]=update(root[x],1,n,z,w);
        }
        if(y==2){
            int k;
            printf("%d\n",Query(root[x],1,n,z));
            root[i]=root[x];
        }
    }
    return 0;
}
2020/9/9 21:00
加载中...