版本比较
[数据结构][主席树][01Trie]P3293 [SCOI2016] 美味
正文
增加 5 行删除 5 行
10 行未改动1112131415161718192 行未改动2223242526272829305 行未改动3637383940414243442 行未改动4748495051525354559 行未改动656667686970717210 行未改动code:```cpp#include<bits/stdc++.h>#define int long longusing namespace std;const int N = 2e5 + 10, M = 1e5;2 行未改动struct node{int ls, rs, sum;}hjt[N << 5];int root[N], cnt;void pushup(int o){hjt[o].sum = hjt[hjt[o].ls].sum + hjt[hjt[o].rs].sum;}void add(int l, int r, int pre, int& now, int x){hjt[++cnt] = hjt[pre]; now = cnt;if(l == r){hjt[now].sum++; return;}if(x <= mid) add(l, mid, hjt[pre].ls, hjt[now].ls, x);5 行未改动if(s <= l && r <= t) return hjt[Ro].sum - hjt[Lo].sum;bool ret = false;if(s <= mid) ret |= check(l, mid, hjt[Lo].ls, hjt[Ro].ls, s, t);if(mid < t) ret |= check(mid + 1, r, hjt[Lo].rs, hjt[Ro].rs, s, t);return ret;}}tr;int n, m;2 行未改动int ret = 0;for(int i = 20; i >= 0; i--){int c = pivot & (1 << i);if(c && !tr.check(0, M, tr.root[l - 1], tr.root[r], ret - ad, ret - ad + (1 << i) - 1)) ret += (1 << i);else if(!c && tr.check(0, M, tr.root[l - 1], tr.root[r], ret - ad + (1 << i), ret - ad + (1 << i + 1) - 1)) ret += (1 << i);}return ret ^ pivot;}9 行未改动int b, x, l, r;cin >> b >> x >> l >> r;cout << solve(b, x, l, r) << "\n";}return 0;}```10 行未改动1112131415161718192 行未改动2223242526272829305 行未改动3637383940414243442 行未改动4748495051525354559 行未改动656667686970717210 行未改动code:```cpp#include<bits/stdc++.h>#define int long longusing namespace std;const int N = 2e5 + 10, M = 1e5;2 行未改动struct node{int ls, rs, sum;}hjt[N << 5];int root[N], cnt;void pushup(int o){hjt[o].sum = hjt[hjt[o].ls].sum + hjt[hjt[o].rs].sum;}void add(int l, int r, int pre, int& now, int x){hjt[++cnt] = hjt[pre]; now = cnt;if(l == r){hjt[now].sum++; return;}if(x <= mid) add(l, mid, hjt[pre].ls, hjt[now].ls, x);5 行未改动if(s <= l && r <= t) return hjt[Ro].sum - hjt[Lo].sum;bool ret = false;if(s <= mid) ret |= check(l, mid, hjt[Lo].ls, hjt[Ro].ls, s, t);if(mid < t) ret |= check(mid + 1, r, hjt[Lo].rs, hjt[Ro].rs, s, t);return ret;}}tr;int n, m;2 行未改动int ret = 0;for(int i = 20; i >= 0; i--){int c = pivot & (1 << i);if(c && !tr.check(0, M, tr.root[l - 1], tr.root[r], ret - ad, ret - ad + (1 << i) - 1)) ret += (1 << i);else if(!c && tr.check(0, M, tr.root[l - 1], tr.root[r], ret - ad + (1 << i), ret - ad + (1 << i + 1) - 1)) ret += (1 << i);}return ret ^ pivot;}9 行未改动int b, x, l, r;cin >> b >> x >> l >> r;cout << solve(b, x, l, r) << "\n";}return 0;}```