92pts求助
查看原帖
92pts求助
171868
sunzz3183楼主2021/10/3 12:59
#include<bits/stdc++.h>
#define res register int
#define ll long long
using namespace std;
ll cnt,n,m,opt,qwq,lstans;
ll a[1000010],root[1000010];
inline ll read() {
	ll ans=0;
	char last=' ',ch=getchar();
	while(ch>'9'||ch<'0') last=ch,ch=getchar();
	while(ch>='0'&&ch<='9') ans=(ans<<1)+(ans<<3)+ch-'0',ch=getchar();
	if(last=='-') ans=-ans;
	return ans;
}const ll mxn=1000010;
struct wtcl{
    ll l,r,sum;
}tree[20000010];
inline void build(ll &rt,ll l,ll r){
    rt=++cnt;
    if(l==r){tree[rt].sum=a[l];return;}
    ll mid=(l+r)>>1;
    build(tree[rt].l,l,mid);build(tree[rt].r,mid+1,r);
}
inline void update(ll l,ll r,ll num,ll pos,ll &rt){
    tree[rt=++cnt]=tree[pos]; 
    ll mid=(l+r)/2;
    if (l==r){tree[rt].sum=qwq; return;}
    if (num<=mid) update(l,mid,num,tree[pos].l,tree[rt].l);
    else update(mid+1,r,num,tree[pos].r,tree[rt].r);
}
inline ll query(ll rt,ll l,ll r,ll num){
    if (l==r) return tree[rt].sum;
    ll mid=(l+r)>>1;
    if (num<=mid) return query(tree[rt].l,l,mid,num);
    else return query(tree[rt].r,mid+1,r,num);
}
int main(){
	//freopen("array.in","r",stdin);
	//freopen("array.out","w",stdout);
    n=read();m=read();
    for (res i=1;i<=n;i++) 
		a[i]=read();
    build(root[0],1,n);
    for (res i=1;i<=m;i++){
        ll t=read(),ot=read();
        if (ot==1){
            ll u=read();qwq=read();
            root[i]=root[t];
            update(1,n,u,root[t],root[i]);
        }else{
            ll u=read();
			lstans=query(root[t],1,n,u);
            printf("%lld\n",lstans);
            root[i]=root[t];
        }
    }
    return 0;
}
2021/10/3 12:59
加载中...