正文
增加 38 行删除 38 行
12345173 行未改动全部展开17918018118218318418518618737 行未改动22522622722822923023123223323423523623731 行未改动26927027127227327427527627727827928028128228328428528628728828929029141 行未改动3333343353363373383393403415 行未改动3473483493503513523533543553563573583593603613623633643659 行未改动3753763773783793803813823833843853863873883893903913922 行未改动39539639739839940040140240340440540640740840941015 行未改动42642742842943043143243343443543643743843944044144254 行未改动4974984995005015025035045054 行未改动51051151251351451551651751851952052152252352452552652752852953091 行未改动62262362462562662762862963022 行未改动65365465565665765865966066122 行未改动68468568668768868969069169224 行未改动7177187197207217227237247254 行未改动73073173273373473573673773873974074174274374474574674774874975075175275375425 行未改动78078178278378478578678778878979079179212 行未改动8058068078088098108118128138 行未改动某个傻鸟的板子实在太长了,又难调bug又多,于是决定精简一下板子。------------### 1.火车头(done)173 行未改动全部展开return 0;}```我放这玩意有意义吗。后面的大概会正经一点。### 4.幂塔```cpp37 行未改动}int main() {scanf("%lld%lld", &n, &p);for (int i = 1; i <= n; i ++) scanf("%lld", &x[i]);printf("%lld", dfs(1, p).first);return 0;}```待填坑,代码略长。31 行未改动scanf("%d%d", &n, &m);for (int i = 1; i <= n; i ++) f[i] = i, cnt[i] = 1, high[i] = 1;while (m --) {scanf("%d", &t);if (t == 1) {//合并scanf("%d%d", &x, &y);int fx = Find(x), fy = Find(y);if (fx != fy) {if (high[fx] < high[fy]) swap(fx, fy);s[++ q] = (node){fx, fy, cnt[fx], cnt[fy], high[fx], high[fy]};if (high[fx] == high[fy]) high[fx] ++;f[fy] = fx, cnt[fx] += cnt[fy];}}if (t == 2) {//查询scanf("%d", &x);printf("%d\n", cnt[Find(x)]);}if (t == 3) {//撤销if (!q) continue;f[s[q].b] = s[q].b, cnt[s[q].a] = s[q].a_cnt, cnt[s[q].b] = s[q].b_cnt;high[s[q].a] = s[q].a_high, high[s[q].b] = s[q].b_high;q --;41 行未改动if (Cmp(tree[t], e, id) == 1) return tree[t];if (Cmp(tree[t], e, id) == 0) return min(e, tree[t]);if (Cmp(tree[t], e, id) == -1) return e;}//返回的是最高且下标最小的线段编号```写这篇文章的真正原因。### 8.斜堆(done)5 行未改动swap(ls[x], rs[x]);return x;}```刚出炉的斜堆(我写左偏树干什么啊)换musician能压成3行### 9.基于状压的线性ST表!(done)```cppstruct RMQ {int n, A[N];int BlockSize;int Pos[N], Belong[N], Pow[M_], Log[N_];int S[N_][M_], Pre[N], Sub[N], F[N];void BuildST() {int id = 0, cur = 0;for (int i = 1; i <= n; i ++) {if (!cur) id ++;9 行未改动for (int i = 1; i <= Log[id]; i ++)for (int j = 1; j + Pow[i] - 1 <= id; j ++)S[j][i] = max(S[j][i - 1], S[j + Pow[i - 1]][i - 1]);}void BuildPreSub() {for (int i = 1; i <= n; i ++)if (Belong[i] != Belong[i - 1]) Pre[i] = A[i];else Pre[i] = max(Pre[i - 1], A[i]);for (int i = n; i >= 1; i --)if (Belong[i] != Belong[i + 1]) Sub[i] = A[i];else Sub[i] = max(Sub[i + 1], A[i]);}void BuildBlock() {static int S[N], Top;for (int i = 1; i <= n; i ++) {if (Belong[i] != Belong[i - 1]) Top = 0;2 行未改动S[++ Top] = i;F[i] |= Pow[Pos[i]];}}void Init() {BlockSize = log2(n) * 1.14;BuildST();BuildPreSub();BuildBlock();}int Query(int L, int R) {if (L > R) {int t = L; L = R, R = t;}int Bl = Belong[L], Br = Belong[R];if (Bl != Br) {15 行未改动printf("%d", R.Query(l, r));return 0;}```信仰。严格$O(n)$~$O(1)$。有一个因为状压长度对$n$大小的隐性要求。### 10.RMQ转笛卡尔树的线性区间RMQ```cpp```没有隐性要求的线性RMQ,但是RMQ转成了LCA又转成了加一减一RMQ。常数较大,但是依然可以在线。### 11.复杂度增加的KMP,但是单次操作严格$O(1)$(done)```cpp54 行未改动cur[x] = i;if (dis[x] - 1 == dis[j] && w[i]) {i64 Nw = ISAP(j, min(In - Out, w[i]));Out += Nw, w[i] -= Nw, w[i ^ 1] += Nw;if (In == Out || dis[s] == n) return Out;}}if (-- cnt[dis[x]] == 0) dis[s] = n;if (dis[s] == n) return Out;4 行未改动}int main() {memset(h, -1, sizeof h);scanf("%lld%lld%lld%lld", &n, &m, &s, &t);for (i64 i = 1; i <= m; i ++) {scanf("%lld%lld%lld", &u, &v, &W);add(u, v, W), add(v, u, 0);}cnt[0] = n;for (i64 i = 1; i <= n; i ++) cur[i] = h[i];while (dis[s] < n) ans += ISAP(s, inf);printf("%lld", ans);return 0;}```91 行未改动if (gF) {if (GetTy(F) == 0) Lson[gF] = x;else Rson[gF] = x;}int A = Lson[x], B = Rson[x];if (GetTy(x) == 0) {Rson[x] = F, Lson[F] = B;if (B) Fa[B] = F;22 行未改动Size[Rt] ++;if (x < val[Rt]) return Insert(Rt, 0, Lson[Rt], x);else if (x == val[Rt]) {cnt[Rt] ++;return Rt;}else return Insert(Rt, 1, Rson[Rt], x);}}22 行未改动if (R) {while (Lson[R]) R = Lson[R];Splay(R);}if (!L || !R) return L + R;else {if (ty == 0) {Rson[L] = R, Fa[R] = L;24 行未改动while (c <= '9' && c >= '0') res = res * 10 + c - '0', c = nc();return res * f;}char obuf[1 << 21], *p3 = obuf;inline void pc(char c) {p3 - obuf <= (1 << 20) ? (*p3 ++ = c) : (fwrite(obuf, p3 - obuf, 1, stdout), p3 = obuf, *p3 ++ = c);}4 行未改动}int main() {n = read(), m = read();for (int i = 1; i <= n; i ++) {x = read();Root = Insert(0, 0, Root, x);Splay(Root);}int ans = 0;while (m --) {opt = read(), x = read();x ^= last;if (opt == 1) {Root = Insert(0, 0, Root, x);Splay(Root);}if (opt == 2) {Root = Find(Root, x);Splay(Root);Root = Delete(Root, 0);}25 行未改动ans ^= last;}// if (opt > 2) write(last), pc('\n');}write(ans);fwrite(obuf, p3 - obuf, 1, stdout);return 0;}```12 行未改动while (c <= '9' && c >= '0') res = res * 10 + c - '0', c = nc();return res * f;}char obuf[1 << 21], *p3 = obuf;inline void pc(char c) {p3 - obuf <= (1 << 20) ? (*p3 ++ = c) : (fwrite(obuf, p3 - obuf, 1, stdout), p3 = obuf, *p3 ++ = c);}inline void write(int x) {8 行未改动12345173 行未改动全部展开17918018118218318418518618737 行未改动22522622722822923023123223323423523623731 行未改动26927027127227327427527627727827928028128228328428528628728828929029141 行未改动3333343353363373383393403415 行未改动3473483493503513523533543553563573583593603613623633643659 行未改动3753763773783793803813823833843853863873883893903913922 行未改动39539639739839940040140240340440540640740840941015 行未改动42642742842943043143243343443543643743843944044144254 行未改动4974984995005015025035045054 行未改动51051151251351451551651751851952052152252352452552652752852953091 行未改动62262362462562662762862963022 行未改动65365465565665765865966066122 行未改动68468568668768868969069169224 行未改动7177187197207217227237247254 行未改动73073173273373473573673773873974074174274374474574674774874975075175275375425 行未改动78078178278378478578678778878979079179212 行未改动8058068078088098108118128138 行未改动某个傻鸟的板子实在太长了,又难调bug又多,于是决定精简一下板子。------------### 1.火车头(done)173 行未改动全部展开return 0;}```我放这玩意有意义吗。后面的大概会正经一点。### 4.幂塔```cpp37 行未改动}int main() {scanf("%lld%lld", &n, &p);for (int i = 1; i <= n; i ++) scanf("%lld", &x[i]);printf("%lld", dfs(1, p).first);return 0;}```待填坑,代码略长。31 行未改动scanf("%d%d", &n, &m);for (int i = 1; i <= n; i ++) f[i] = i, cnt[i] = 1, high[i] = 1;while (m --) {scanf("%d", &t);if (t == 1) {//合并scanf("%d%d", &x, &y);int fx = Find(x), fy = Find(y);if (fx != fy) {if (high[fx] < high[fy]) swap(fx, fy);s[++ q] = (node){fx, fy, cnt[fx], cnt[fy], high[fx], high[fy]};if (high[fx] == high[fy]) high[fx] ++;f[fy] = fx, cnt[fx] += cnt[fy];}}if (t == 2) {//查询scanf("%d", &x);printf("%d\n", cnt[Find(x)]);}if (t == 3) {//撤销if (!q) continue;f[s[q].b] = s[q].b, cnt[s[q].a] = s[q].a_cnt, cnt[s[q].b] = s[q].b_cnt;high[s[q].a] = s[q].a_high, high[s[q].b] = s[q].b_high;q --;41 行未改动if (Cmp(tree[t], e, id) == 1) return tree[t];if (Cmp(tree[t], e, id) == 0) return min(e, tree[t]);if (Cmp(tree[t], e, id) == -1) return e;}//返回的是最高且下标最小的线段编号```写这篇文章的真正原因。### 8.斜堆(done)5 行未改动swap(ls[x], rs[x]);return x;}```刚出炉的斜堆(我写左偏树干什么啊)换musician能压成3行### 9.基于状压的线性ST表!(done)```cppstruct RMQ {int n, A[N];int BlockSize;int Pos[N], Belong[N], Pow[M_], Log[N_];int S[N_][M_], Pre[N], Sub[N], F[N];void BuildST() {int id = 0, cur = 0;for (int i = 1; i <= n; i ++) {if (!cur) id ++;9 行未改动for (int i = 1; i <= Log[id]; i ++)for (int j = 1; j + Pow[i] - 1 <= id; j ++)S[j][i] = max(S[j][i - 1], S[j + Pow[i - 1]][i - 1]);}void BuildPreSub() {for (int i = 1; i <= n; i ++)if (Belong[i] != Belong[i - 1]) Pre[i] = A[i];else Pre[i] = max(Pre[i - 1], A[i]);for (int i = n; i >= 1; i --)if (Belong[i] != Belong[i + 1]) Sub[i] = A[i];else Sub[i] = max(Sub[i + 1], A[i]);}void BuildBlock() {static int S[N], Top;for (int i = 1; i <= n; i ++) {if (Belong[i] != Belong[i - 1]) Top = 0;2 行未改动S[++ Top] = i;F[i] |= Pow[Pos[i]];}}void Init() {BlockSize = log2(n) * 1.14;BuildST();BuildPreSub();BuildBlock();}int Query(int L, int R) {if (L > R) {int t = L; L = R, R = t;}int Bl = Belong[L], Br = Belong[R];if (Bl != Br) {15 行未改动printf("%d", R.Query(l, r));return 0;}```信仰。严格$O(n)$~$O(1)$。有一个因为状压长度对$n$大小的隐性要求。### 10.RMQ转笛卡尔树的线性区间RMQ```cpp```没有隐性要求的线性RMQ,但是RMQ转成了LCA又转成了加一减一RMQ。常数较大,但是依然可以在线。### 11.复杂度增加的KMP,但是单次操作严格$O(1)$(done)```cpp54 行未改动cur[x] = i;if (dis[x] - 1 == dis[j] && w[i]) {i64 Nw = ISAP(j, min(In - Out, w[i]));Out += Nw, w[i] -= Nw, w[i ^ 1] += Nw;if (In == Out || dis[s] == n) return Out;}}if (-- cnt[dis[x]] == 0) dis[s] = n;if (dis[s] == n) return Out;4 行未改动}int main() {memset(h, -1, sizeof h);scanf("%lld%lld%lld%lld", &n, &m, &s, &t);for (i64 i = 1; i <= m; i ++) {scanf("%lld%lld%lld", &u, &v, &W);add(u, v, W), add(v, u, 0);}cnt[0] = n;for (i64 i = 1; i <= n; i ++) cur[i] = h[i];while (dis[s] < n) ans += ISAP(s, inf);printf("%lld", ans);return 0;}```91 行未改动if (gF) {if (GetTy(F) == 0) Lson[gF] = x;else Rson[gF] = x;}int A = Lson[x], B = Rson[x];if (GetTy(x) == 0) {Rson[x] = F, Lson[F] = B;if (B) Fa[B] = F;22 行未改动Size[Rt] ++;if (x < val[Rt]) return Insert(Rt, 0, Lson[Rt], x);else if (x == val[Rt]) {cnt[Rt] ++;return Rt;}else return Insert(Rt, 1, Rson[Rt], x);}}22 行未改动if (R) {while (Lson[R]) R = Lson[R];Splay(R);}if (!L || !R) return L + R;else {if (ty == 0) {Rson[L] = R, Fa[R] = L;24 行未改动while (c <= '9' && c >= '0') res = res * 10 + c - '0', c = nc();return res * f;}char obuf[1 << 21], *p3 = obuf;inline void pc(char c) {p3 - obuf <= (1 << 20) ? (*p3 ++ = c) : (fwrite(obuf, p3 - obuf, 1, stdout), p3 = obuf, *p3 ++ = c);}4 行未改动}int main() {n = read(), m = read();for (int i = 1; i <= n; i ++) {x = read();Root = Insert(0, 0, Root, x);Splay(Root);}int ans = 0;while (m --) {opt = read(), x = read();x ^= last;if (opt == 1) {Root = Insert(0, 0, Root, x);Splay(Root);}if (opt == 2) {Root = Find(Root, x);Splay(Root);Root = Delete(Root, 0);}25 行未改动ans ^= last;}// if (opt > 2) write(last), pc('\n');}write(ans);fwrite(obuf, p3 - obuf, 1, stdout);return 0;}```12 行未改动while (c <= '9' && c >= '0') res = res * 10 + c - '0', c = nc();return res * f;}char obuf[1 << 21], *p3 = obuf;inline void pc(char c) {p3 - obuf <= (1 << 20) ? (*p3 ++ = c) : (fwrite(obuf, p3 - obuf, 1, stdout), p3 = obuf, *p3 ++ = c);}inline void write(int x) {8 行未改动