8pts求调 AC on Sub0#1
查看原帖
8pts求调 AC on Sub0#1
759326
DAMDAM楼主2023/11/25 14:20
#include<cstdio>
#include<algorithm> 
using namespace std;
typedef long long ll;
const int maxn = 1e6 + 5;
ll d[maxn << 7], a[maxn];
int ls[maxn << 7], rs[maxn << 7], rt[maxn << 7], len, n;
void Build(const int &s, const int &t, int &p) {
	p = ++len;
	if (s == t) {
		d[p] = a[s];
		return;
	}
	int mid = s + ((t - s) >> 1);
	Build(s, mid, ls[p]), Build(mid + 1, t, rs[p]);
}

void Update(const int &x, const int &root, const ll &c, const int &s, const int &t, int &p) {
	ls[p = ++len] = ls[root], rs[p] = rs[root];
	if (s == t) {
		d[p] = c;
		return;
	}
	int mid = s + ((t - s) >> 1);
	if (x <= mid) Update(x, ls[root], c, s, mid, ls[p]);
	else Update(x, rs[root], c, mid + 1, t, rs[p]);
}

ll Get(const int &x, const int &s, const int &t, int &p) {
	if (s == t) return d[p];
	int mid = s + ((t - s) >> 1);
	return x <= mid ? Get(x, s, mid, ls[p]) : Get(x, mid + 1, t, rs[p]);
}

int main() {
	int m;
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; ++i) scanf("%lld", a + i);
	Build(1, n, *rt);
	for (int i = 1, v, tp, x, val; i <= m; ++i) {
		scanf("%d%d%d", &v, &tp, &x);
		if (tp == 1) scanf("%d", &val), Update(x, rt[v], val, 1, n, rt[i]);
		else printf("%lld", Get(x, 1, n, rt[i] = rt[v])), putchar(10);	
	}
	return 0;
}

2023/11/25 14:20
加载中...