开始想想直接模拟复杂度是对的就写了 multiset,没想到
multiset 的 lower_bound 太慢了 T
了几个点。
Upd : 经提醒应该是 count 函数太慢了,官网描述是
"Logarithmic in size
and linear in the number of matches" ,也就是说复杂度是 \(\mathcal{O}(k+\log n)\) ,其中 \(k\) 是查询数字的出现次数,所以加入 \(10^5\) 个点之后,多查几次就超时了。
inlineintrd(){ int x = 0; bool f = 0; char c = getchar(); for (; !isdigit(c); c = getchar()) f |= (c == '-'); for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48); return f ? -x : x; }
map<int, int> cnt;
set<int> s;
intmain(){ int n = rd(); for (int i = 1; i <= n; ++i) { int op = rd(); if (op == 1) { int x = rd(); ++cnt[x]; if (cnt[x] == 1) s.insert(x); } elseif (op == 2) { int x = rd(); int t = min(rd(), cnt[x]); cnt[x] -= t; if (cnt[x] == 0) s.erase(x); } elseprintf("%d\n", (*--s.end()) - (*s.begin())); } return0; }
inlineintrd(){ int x = 0; bool f = 0; char c = getchar(); for (; !isdigit(c); c = getchar()) f |= (c == '-'); for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48); return f ? -x : x; }
intgcd(int a, int b){ return b ? gcd(b, a % b) : a; }
intmain(){ int n = rd(), a = rd(), b = rd(); ll sum = 1ll * n * (n + 1) / 2; int ka = n / a; int kb = n / b; sum -= 1ll * a * ka * (ka + 1) / 2; sum -= 1ll * b * kb * (kb + 1) / 2; ll lcm = 1ll * a * b / gcd(a, b); ll kl = n / lcm; sum += 1ll * lcm * kl * (kl + 1) / 2; printf("%lld\n", sum); return0; }
inlineintrd(){ int x = 0; bool f = 0; char c = getchar(); for (; !isdigit(c); c = getchar()) f |= (c == '-'); for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48); return f ? -x : x; }
#define N 1007 #define M 5007 #define mod 998244353
int f[N][M], sum[N][M];
inlineintfpow(int x, int t){ int res = 1; for (; t; t >>= 1, x = 1ll * x * x % mod) if (t & 1) res = 1ll * res * x % mod; return res; }
intmain(){ int n = rd(), m = rd(), k = rd(); if (k == 0) {printf("%d\n", fpow(m, n)); return0;} for (int i = 1; i <= m; ++i) { f[1][i] = 1; sum[1][i] = i; } for (int i = 2; i <= n; ++i) { for (int j = 1; j <= m; ++j) { int l = max(0, j - k); int r = min(m, j + k - 1); f[i][j] = (sum[i - 1][m] - sum[i - 1][r] + mod) % mod; f[i][j] = (f[i][j] + sum[i - 1][l]) % mod; } for (int j = 1; j <= m; ++j) sum[i][j] = (sum[i][j - 1] + f[i][j]) % mod; } printf("%d\n", sum[n][m]); return0; }
inlineintrd(){ int x = 0; bool f = 0; char c = getchar(); for (; !isdigit(c); c = getchar()) f |= (c == '-'); for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48); return f ? -x : x; }
#define mid ((l + r) >> 1) #define N 200007
int tot, rttot;
structnode { int ls, rs; ll sum; } c[N << 6];
int rot[N], lst[N];
ll x[N];
intcopy(int rt){ c[++tot] = c[rt]; return tot; }
voidupd(int &rt, int l, int r, int L, int R, int x){ rt = copy(rt); if (L <= l && r <= R) { c[rt].sum += x; return; } if (L <= mid) upd(c[rt].ls, l, mid, L, R, x); if (R > mid) upd(c[rt].rs, mid + 1, r, L, R, x); }
ll query(int rtl, int rtr, int l, int r, int p){ ll res = c[rtr].sum - c[rtl].sum; if (l == r) return res; if (p <= mid) res += query(c[rtl].ls, c[rtr].ls, l, mid, p); else res += query(c[rtl].rs, c[rtr].rs, mid + 1, r, p); return res; }
intmain(){ int n = rd(), m = rd(), q = rd(); for (int i = 1; i <= q; ++i) { int op = rd(); if (op == 1) { ++rttot; rot[rttot] = rot[rttot - 1]; int l = rd(), r = rd(), v = rd(); upd(rot[rttot], 1, m, l, r, v); } elseif (op == 2) { int p = rd(); x[p] = rd(); lst[p] = rttot; } else { int row = rd(), col = rd(); printf("%lld\n", x[row] + query(rot[lst[row]], rot[rttot], 1, m, col)); } } return0; }
inline ll rd(){ ll x = 0; bool f = 0; char c = getchar(); for (; !isdigit(c); c = getchar()) f |= (c == '-'); for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48); return f ? -x : x; }
rope<int> s;
intmain(){ int n = rd(); ll L = rd(), R = rd(); ll l = 0, r = 0; for (int i = 0; i <= n; ++i) s.push_back(i); for (int i = 1; i <= n; ++i) { l = r + 1; r = l + n - i - 1; if (L <= r && R >= l) { int ll = max(l, L), rr = min(r, R); int pl = i + 1 + ll - l; int pr = i + 1 + rr - l; int x = s[pr]; s.erase(pr, 1); s.insert(pl, s[i]); s.erase(i, 1); s.insert(i, x); } } for (int i = 1; i <= n; ++i) printf("%d ", s[i]); return0; }