正文
增加 104 行删除 70 行
196 行未改动全部展开197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285196 行未改动全部展开- $0\le i+j<C$:两端分开取,比如 $0$ 和 $C-1$、$1$ 和 $C-2$ 这种。multiset 直接搞。欸,扔下代码吧。::::success[code]#include <bits/stdc++.h>using namespace std;constexpr int N = 5e5+5;int n, p, lst;multiset<int> S, mut;inline int best(int x){auto it = S.lower_bound(p-x);if (it == S.begin()) return -1;--it;if (*it == x) {if (S.count(x) > 1) return x;if (it == S.begin()) return -1;return *prev(it);}return *it;}inline bool chk(int x, int y){if (y == -1) return 0;int z = best(y); return x == z;}inline void ins(int x){int y = best(x);bool added = false;if (y != -1){int z = best(y);if (z == -1 || x > z){if (z != -1 && chk(y, z)){auto it = mut.find(y + z);if (it != mut.end()) mut.erase(it);}mut.insert(x + y);added = true;} else if (x == z) {// (y,z) is already mutual with sum y+z = x+y in mut.// After insertion (duplicate of z), (x_new,y) is also mutual// via the same pair 鈥?x+y = z+y already exists in mut.// Don't add another copy, but mark as active for second part.added = true;}}S.insert(x);int y2 = best(x);if (y2 != -1 && y2 != y){if (y != -1 && added){auto it = mut.find(x + y);if (it != mut.end()) mut.erase(it);}mut.insert(x + y2);}}inline void del(int x){int y = best(x);bool was = (y != -1 && chk(x, y));if (was){auto it = mut.find(x + y);if (it != mut.end()) mut.erase(it);}S.erase(S.find(x));if (was && y != -1){int z = best(y);if (z != -1 && chk(y, z)) mut.insert(y+z);}}inline int qry(){if (S.size() < 2) return -1;int mx = *S.rbegin(), se = S.count(mx) >= 2 ? mx : *next(S.rbegin()), ans = (mx+se)%p;if (!mut.empty()) ans = max(ans, *mut.rbegin()); return ans;}signed main(){// freopen(".in","r",stdin); freopen(".out","w",stdout);ios::sync_with_stdio(0); cin.tie(0);cin >> n >> p; while (n--){int o, x; cin >> o >> x; x ^= lst, x %= p;o == 1 ? ins(x) : del(x);int s = qry(); if (s == -1){ cout << "EE\n"; lst = 0; } else cout << (lst = s) << "\n";} return 0;}::::## [P6108 [Ynoi2009] rprsvq](https://www.luogu.com.cn/problem/P6108)Ynmo。处理方差部分可以类比 [P1471 方差](https://www.luogu.com.cn/problem/P1471)。196 行未改动全部展开197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319196 行未改动全部展开- $0\le i+j<C$:两端分开取,比如 $0$ 和 $C-1$、$1$ 和 $C-2$ 这种。multiset 直接搞。## [P6108 [Ynoi2009] rprsvq](https://www.luogu.com.cn/problem/P6108)Ynmo。处理方差部分可以类比 [P1471 方差](https://www.luogu.com.cn/problem/P1471)。## [P5048 [Ynoi2019 模拟赛] Yuno loves sqrt technology III](https://www.luogu.com.cn/problem/P5048)离散化 -> 预处理 -> 分块。完全不需要卡常。很舒服。## [P5047 [Ynoi2019 模拟赛] Yuno loves sqrt technology II](https://www.luogu.com.cn/problem/P5047)和 [P5046 [Ynoi2019 模拟赛] Yuno loves sqrt technology I](https://www.luogu.com.cn/problem/P5046) 的区别在于此题是 **序列** 和 **不强制在线**。所以我们可以愉快地对询问排序、分块,进行一些莫队操作~ 不过我们还需要把莫队没做到的操作保存下来(`v1` 和 `v2` 数组),然后再做一下(`slv` 函数)。谔谔感觉没说清楚。不管了。莫队二次离线板子。::::success[code]```#include <bits/stdc++.h>using namespace std;constexpr int N = 1e5+5;#define ll long longint n, m, a[N], aa[N], tr[N], cnt1[N], cnt2[N], pB, V, B, S, L[N], R[N], lp[N], bp[N]; ll sum1[N], sum2[N], res[N];// cnt1 - i 作为右端点时, 加入 a[i] 带来的新增逆序对数 / sum1 - cnt1 的 前缀和 / cnt2 和 sum2 是后缀// lp - 在当前块内,已插入元素中值 ≤ v 的数量 / bp - 已插入元素总数struct qury{ int l, r, i; } q[N];struct node{ int l, r, x, i; }; vector<node> v1[N], v2[N];inline int qry(int x){ int s = 0; for ( ; x; x -= x&-x) s += tr[x]; return s; }inline void add(int x, int k){ for ( ; x <= n; x += x&-x) tr[x] += k; }inline int get(int x){ return (x-1)/B+1; }inline void init(){B = sqrt(V); if (B > 355) B = 355; S = ceil(1.0*V/B);for (int i = 1; i <= S; i++) L[i] = (i-1)*B+1, R[i] = i*B; R[S] = V;}inline int qry1(int x){ // >xif (x >= V) return 0; int b = get(x);return bp[S] - (b>1?bp[b-1]:0) - lp[x];}inline int qry2(int x){ // <xif (x <= 1) return 0; int b = get(x-1);return (b>0?bp[b-1]:0) + lp[x-1];}inline void ins(int x){int b = get(x);for (int i = x; i <= R[b]; i++) lp[i]++;for (int i = b; i <= S; i++) bp[i]++;}void slv(){for (int i = 1; i <= n; i++){for (node &j : v1[i]){ll cnt = 0;for (int k = j.l; k <= j.r; k++) cnt += qry1(a[k]);res[j.i] += j.x*cnt;} ins(a[i]);} memset(lp, 0, sizeof lp); memset(bp, 0, sizeof bp);for (int i = n; i >= 1; i--){for (node &j : v2[i]){ll cnt = 0;for (int k = j.l; k <= j.r; k++) cnt += qry2(a[k]);res[j.i] += j.x*cnt;} ins(a[i]);} memset(lp, 0, sizeof lp); memset(bp, 0, sizeof bp);}signed main(){// freopen(".in","r",stdin); freopen(".out","w",stdout);ios::sync_with_stdio(0); cin.tie(0);cin >> n >> m; pB = 355;for (int i = 1; i <= n; i++) cin >> a[i], aa[i] = a[i];sort(aa + 1,aa + n + 1); int nn = unique(aa + 1, aa + n +1) - aa - 1;for (int i = 1; i <= n; i++) a[i] = lower_bound(aa + 1, aa + nn + 1, a[i]) - aa, V = max(V, a[i]);for (int i = 1; i <= m; i++) cin >> q[i].l >> q[i].r, q[i].i = i;sort(q + 1, q + m + 1, [](const qury& a, const qury& b){if (a.l/pB != b.l/pB) return a.l < b.l;return (a.l/pB & 1) ? a.r > b.r : a.r < b.r;});for (int i = 1; i <= n; i++) cnt1[i] = (i-1-qry(a[i])), sum1[i] = sum1[i-1]+cnt1[i], add(a[i], 1);memset(tr, 0, sizeof tr);for (int i = n; i >= 1; i--) cnt2[i] = qry(a[i]-1), sum2[i] = sum2[i+1]+cnt2[i], add(a[i], 1);for (int i = 1, l = 1, r = 0; i <= m; i++){if (r < q[i].r) res[q[i].i] += sum1[q[i].r]-sum1[r], v1[l].push_back({r+1, q[i].r, -1, q[i].i}), r = q[i].r;if (r > q[i].r) res[q[i].i] -= sum1[r]-sum1[q[i].r], v1[l].push_back({q[i].r+1, r, 1, q[i].i}), r = q[i].r;if (l < q[i].l) res[q[i].i] -= sum2[l]-sum2[q[i].l], v2[r].push_back({l, q[i].l-1, 1, q[i].i}), l = q[i].l;if (l > q[i].l) res[q[i].i] += sum2[q[i].l]-sum2[l], v2[r].push_back({q[i].l, l-1, -1, q[i].i}), l = q[i].l;} init(); slv();for (int i = 1; i <= m;i ++) res[q[i].i] += res[q[i-1].i];for (int i = 1; i <= m;i ++) cout << res[i] << "\n";return 0;}```::::# Lv.3## [P5356 [Ynoi Easy Round 2017] 由乃打扑克](https://www.luogu.com.cn/problem/P5356)~~作业题就先写了~~其实感觉不该给这么高的。大体就是 二分+分块。块内or散块直接改,整块打 tag。也没卡常就过了啊。# Lv.NONE这个题单毕竟只有 31 题嘛……qwq这里收录一些我暂时不太好评的。能给 Lv 的我都给了。## [P6781 [Ynoi2008] rupq](https://www.luogu.com.cn/problem/P6781)好像是第一次挑战黑 Ynoi(?)吓哭了。为此还去学了 WBLT。主要是非常难写吧。感觉没啥好记录的。后面调不出来交给 AI 的。哎。我不仅菜还摆。