1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
| #include <bits/stdc++.h> #define lson l, mid, ls[x] #define rson mid+1, r, rs[x] #define LL long long #define debug using namespace std;
const int N = 4e5+66;
int ls[N * 19], rs[N * 19], si[N * 19]; int n, tot, f[N], root[N], tag[N * 19]; int m = 1e9; double sum[N * 19];
inline void pushdown(int x) { if (tag[x]) { si[ls[x]] = si[rs[x]] = 0; sum[ls[x]] = sum[rs[x]] = 0; tag[ls[x]] = tag[rs[x]] = 1; tag[x] = 0; } }
inline int find(int x) {return f[x] == x ? f[x] : f[x] = find(f[x]);}
inline void add(int p, int a, double v, int l, int r, int &x) { if (!x) x = ++ tot; si[x] += a, sum[x] += a*v; if (l == r) return; pushdown(x); int mid = (l + r) >> 1; if (p <= mid) add(p, a, v, lson); else add(p, a, v, rson); }
inline void del(int b, int e, int l, int r, int x) { if (!x) return; if (b <= l && r <= e) { si[x] = 0, sum[x] = 0, tag[x] = 1; return; } pushdown(x); int mid = (l + r) >> 1; if (b <= mid) del(b, e, lson); if (e > mid) del(b, e, rson); si[x] = si[ls[x]] + si[rs[x]]; sum[x] = sum[ls[x]] + sum[rs[x]]; }
inline int querysi(int b, int e, int l, int r, int x) { if (!x) return 0; if (b <= l && r <= e) return si[x]; pushdown(x); int mid = (l + r) >> 1, res = 0; if (b <= mid) res += querysi(b, e, lson); if (e > mid) res += querysi(b, e, rson); return res; }
inline int find(int k, int l, int r, int x) { if (l == r) return l; pushdown(x); int mid = (l + r) >> 1; if (k <= si[ls[x]]) return find(k, lson); else return find(k - si[ls[x]], rson); }
inline int merge(int x, int y) { if (!x || !y) return x+y; si[x] += si[y], sum[x] += sum[y]; pushdown(x); pushdown(y); ls[x] = merge(ls[x], ls[y]); rs[x] = merge(rs[x], rs[y]); return x; }
inline int thestars() { int T, c, x, y, t; scanf ("%d", &T); while (T --) { scanf ("%d%d", &c, &x); switch(c) { case 1: add(x, 1, log(x), 1, m, root[++ n]), f[n] = n; break; case 2: { scanf ("%d", &y); x = find(x), y = find(y); if (x != y) { f[y] = x; root[x] = merge(root[x], root[y]); } break; } case 3: { x = find(x); scanf ("%d", &y); t = querysi(1, y, 1, m, root[x]); del(1, y, 1, m, root[x]); add(y, t, log(y), 1, m, root[x]); break; } case 4: { x = find(x); scanf ("%d", &y); t = querysi(y, m, 1, m, root[x]); del(y, m, 1, m, root[x]); add(y, t, log(y), 1, m, root[x]); break;
} case 5: { x = find(x); scanf ("%d", &y); cout << find(y, 1, m, root[x]) << '\n'; break; } case 6: { x = find(x); scanf ("%d", &y); y = find(y); printf("%d\n", sum[root[x]] > sum[root[y]]); break; } default : x = find(x); cout << si[root[x]] << '\n'; } } return 0; }
int youngore = thestars();
signed main() {;}
|