莫队+值域分块 36pts 求调教,调出来左边和右边的同学一起吃键盘

P4137 Rmq Problem / mex

@[zhangjiting](/user/754311) 要吃自己吃。我只吃柠檬。
by STARS_czy @ 2024-03-14 17:30:23


@[zhangjiting](/user/754311) ```cpp #include <bits/stdc++.h> using namespace std; #define int long long const int N = 2e5 + 5, B = 455; struct node { int l, r, id; }a[N]; int n, q, x[N], ans[N], cnt = 0, c[N], ck[N]; vector<int> v; bool cmp(node _x, node _y) { if (_x.l / B != _y.l / B) { return _x.l / B < _y.l / B; } return _x.r < _y.r; } void check(int u, int op) { c[u] += op; if (op == 1) { if (c[u] == 1) { ck[u / B]++; } } else { if (c[u] == 0) { ck[u / B]--; } } } signed main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n >> q; for (int i = 1; i <= n; i++) { cin >> x[i]; } for (int i = 1; i <= q; i++) { cin >> a[i].l >> a[i].r; a[i].id = i; } sort(a + 1, a + q + 1, cmp); for (int i = 1, lt = 1, rt = 0; i <= q; i++) { while (lt < a[i].l) { check(x[lt], -1); lt++; } while (rt < a[i].r) { rt++; check(x[rt], 1); } while (lt > a[i].l) { lt--; check(x[lt], 1); } while (rt > a[i].r) { check(x[rt], -1); rt--; } int tmp = 0; for (int i = 0; i <= 450; i++) { if (ck[i] < B) { for (int j = i * 455; j <= (i + 1) * 455; j++) { if (!c[j]) { tmp = j; break; } } break; } } ans[a[i].id] = tmp; } for (int i = 1; i <= q; i++) { cout << ans[i] << "\n"; } return 0; } ```
by Third_eye @ 2024-04-18 16:17:43


@[Third_eye](/user/820057) 我想知道我自己哪里错了
by zhangjiting @ 2024-04-18 16:20:45


@[zhangjiting](/user/754311) ORZ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
by Third_eye @ 2024-04-18 16:22:45


|