恩。。什么树状数组套主席树?大概是可以修改并且支持前缀减法的数据结构吧。。。
咦。可以离线?上莫队不就行了,干嘛要数据结构。。。
哦还要修改,那就三维莫队就好了,happy ending!

1 /************************************************************** 2 Problem: 2120 3 User: rausen 4 Language: C++ 5 Result: Accepted 6 Time:488 ms 7 Memory:5540 kb 8 ****************************************************************/ 9 10 #include <cstdio> 11 #include <cmath> 12 #include <algorithm> 13 14 using namespace std; 15 const int N = 1e4 + 5; 16 const int cnt_C = 1e6 + 5; 17 const int Maxlen = N * 35; 18 19 int n, m, sz, cnt_b; 20 int w[N], c[N], pre[N]; 21 int now; 22 int cnt_c, cnt_q; 23 int ans[N], vis[N], cnt[cnt_C]; 24 char buf[Maxlen], *ch = buf; 25 int Len; 26 27 struct oper_change { 28 int x, y, pre; 29 oper_change() {} 30 oper_change(int _x, int _y, int _p) : x(_x), y(_y), pre(_p) {} 31 } oc[N]; 32 33 struct oper_query { 34 int x, y, id, t; 35 oper_query() {} 36 oper_query(int _x, int _y, int _i, int _t) : x(_x), y(_y), id(_i), t(_t) {} 37 38 inline bool operator < (const oper_query &X) const { 39 return w[x] == w[X.x] ? w[y] == w[X.y] ? t < X.t : w[y] < w[X.y] : w[x] < w[X.x]; 40 } 41 } oq[N]; 42 43 inline int read() { 44 int x = 0; 45 while (*ch < '0' || '9' < *ch) ++ch; 46 while ('0' <= *ch && *ch <= '9') 47 x = x * 10 + *ch - '0', ++ch; 48 return x; 49 } 50 51 inline void reverse(int p) { 52 if (vis[p]) { 53 if ((--cnt[c[p]]) == 0) --now; 54 } else { 55 if ((++cnt[c[p]]) == 1) ++now; 56 } 57 vis[p] ^= 1; 58 } 59 60 inline int update(int p, int C) { 61 if (vis[p]) { 62 reverse(p); 63 c[p] = C; 64 reverse(p); 65 } else c[p] = C; 66 } 67 68 int main() { 69 Len = fread(ch, 1, Maxlen, stdin); 70 buf[Len] = '