正文
增加 4 行删除 4 行
43 行未改动44454647484950515221 行未改动747576777879808182838485864 行未改动91929394959697989912 行未改动43 行未改动void build(int &p, int l, int r) {p = ++ cnt;if (l == r) {tr[p].sum = a[l];return ;}int mid = l + r >> 1;build(tr[p].l, l, mid);build(tr[p].r, mid + 1, r);21 行未改动}signed 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(root[0], 1, n);for (int i = 1, v, opt, p, c; i <= m; i ++) {cin >> v >> opt >> p;if (opt == 1) {4 行未改动cout << query(root[i], 1, n, p) << '\n';}}return 0;}```由于本题是单点修改单点查询,所以并没有什么好说的。(甚至连非根非叶子节点都不用管)### 模板[P3834 【模板】可持久化线段树 2](https://www.luogu.com.cn/problem/P3834)#### 题意:12 行未改动43 行未改动44454647484950515221 行未改动747576777879808182838485864 行未改动91929394959697989912 行未改动43 行未改动void build(int &p, int l, int r) {p = ++ cnt;if (l == r) {tr[p].sum = a[l];return ;}int mid = l + r >> 1;build(tr[p].l, l, mid);build(tr[p].r, mid + 1, r);21 行未改动}signed 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(root[0], 1, n);for (int i = 1, v, opt, p, c; i <= m; i ++) {cin >> v >> opt >> p;if (opt == 1) {4 行未改动cout << query(root[i], 1, n, p) << '\n';}}return 0;}```由于本题是单点修改单点查询,所以并没有什么好说的。(甚至连非根非叶子节点都不用管)### 模板[P3834 【模板】可持久化线段树 2](https://www.luogu.com.cn/problem/P3834)#### 题意:12 行未改动