wronga
查看原帖
wronga
786154
zhanxiangkun楼主2024/8/6 15:22
#include <bits/stdc++.h>
using namespace std;
const int N = 1000001;
int n,a[N],m,tot,root[N],cnt;
struct Seg_tree{
	int lc,rc,dat;
}tr[30*N];
int build(int l,int r){
	int p = ++tot;
	if (l==r){tr[p].dat=a[l];return p;}
	int mid=(l+r)/2;
	tr[p].lc=build(l,mid);
	tr[p].rc=build(mid+1,r);
	return p;
}
int insert(int now,int l,int r,int x,int val){
	int p = ++ tot  ;
	tr[p] = tr[now];
	if (l==r){tr[p].dat=val; return  p;}
	int mid=(l+r)/2;
	if (x<=mid)
		tr[p].lc = insert(tr[now].lc,l,mid,x,val);
	else
		tr[p].rc = insert(tr[now].rc,mid+1,r,x,val);
	return p;
}
int ask(int now,int l,int r,int x){
	if (l == r) return tr[now].dat;
	int mid=(l+r)/2;
	if (x<=mid) return ask(tr[now].lc,l,mid,x);
	else return ask(tr[now].rc,mid+1,r,x);
}
int main(){
	ios::sync_with_stdio(0);
	cin >> n >> m;
	for (int i=1;i<=n;i++) cin >> a[i];
	root[0] = build(1,n);
	while (m--){
		int vi,op,positive,value;
		cin >> vi >> op >> positive;
		if (op==1)
		{
			cin >> value;
			cnt+=1;
			root[cnt]=insert(root[vi],1,n,positive,value);
		}
		else cout << ask(root[vi],1,n,positive) << '\n';
	}
	return 0;
}
2024/8/6 15:22
加载中...