0分RE求调
查看原帖
0分RE求调
1320239
CSZ7943楼主2024/12/9 19:29
#include<iostream>
using namespace std;
int n,m,a[1000005];
struct node{
	int ls,rs,dat;
}tree[5000005];
int rt[1000005];
int id;
void build(int l,int r,int &p){
	p=++id;
	if(l==r){
		tree[p].dat=a[l];
		return;
	}
	int mid=(l+r)/2;
	build(l,mid,tree[p].ls);
	build(mid+1,r,tree[p].rs);
}
void update(int l,int r,int fa,int &p,int x,int y){
	p=++id;
	tree[p]=tree[fa];
	if(l==r){
		tree[p].dat=y;
		return;
	}
	int mid=(l+r)/2;
	if(x<=mid){
		update(l,mid,tree[fa].ls,tree[p].ls,x,y);
	}else{
		update(mid+1,r,tree[fa].rs,tree[p].rs,x,y);
	}
}
int ask(int l,int r,int p,int x){
	if(l==r){
		return tree[p].dat;
	}
	int mid=(l+r)/2;
	if(x<=mid){
		ask(l,mid,tree[p].ls,x);
	}else{
		ask(mid+1,r,tree[p].rs,x);
	}
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	build(1,n,rt[0]);
	for(int i=1;i<=m;i++){
		int t,op,x,y;
		cin>>t>>op;
		if(op==1){
			cin>>x>>y;
			update(1,n,rt[t],rt[i],x,y);
		}else{
			cin>>x;
			cout<<ask(1,n,rt[t],x)<<"\n";
		}
	}
	return 0;
} 
2024/12/9 19:29
加载中...