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
| #include<bits/stdc++.h> #define ok cout << "ok" << endl; using namespace std; typedef long long ll; typedef vector<int> vi; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const double PI = acos(-1.0); const int INF=0x3f3f3f3f; const ll LINF=0x3f3f3f3f3f3f3f3f; const int N=2e5+9; const double Eps=1e-7;
set<int> s; map<int, int> ma; int len, n, m, a[N], cnt[N], se[N], x, y, tot, timer, l, r, last[N], an[N], op, flag[N], dis, up;
struct node { int l, r, id, lblock, rblock, timer; node() {} node(int l, int r, int id, int timer): l(l), r(r), id(id), timer(timer) { this->lblock = l / len; this->rblock = r / len; } bool operator < (const node t) const { if(lblock != t.lblock) return lblock < t.lblock; if(rblock != t.rblock) return rblock < t.rblock; return timer < t.timer; } }q[N];
struct node1 { int x, val, last; node1() {} node1(int x, int val, int last): x(x), val(val), last(last) {} }chg[N];
void sub(int x) { int &t = cnt[a[x]]; se[t]--; se[--t]++; flag[x] = 0; }
void add(int x) { int &t = cnt[a[x]]; se[t]--; se[++t]++; flag[x] = 1; }
void modify(int x, int val) { if(!flag[x]) a[x] = val; else { sub(x); a[x] = val; add(x); } }
int main(void) { if(fopen("in", "r")!=NULL) {freopen("in", "r", stdin); freopen("out", "w", stdout);} while(~scanf("%d%d", &n, &m)) { len = pow(n, 2.0/3); for(int i = 1; i <= n; i++) { scanf("%d", a + i); s.insert(a[i]); last[i] = a[i]; } for(int i = 0; i < m; i++) { scanf("%d%d%d", &op, &x, &y); if(op == 1) { q[tot] = node{x, y, tot, timer}; tot++; } else { timer++; chg[timer] = node1{x, y, last[x]}; s.insert(y); last[x] = y; } } for(auto i: s) ma[i] = dis++; for(int i = 1; i <= n; i++) a[i] = ma[a[i]]; for(int i = 1; i <= timer; i++) chg[i].val = ma[chg[i].val], chg[i].last = ma[chg[i].last];
l = 1, r = 0, timer = 0; up = sqrt(2 * n); sort(q, q + tot); for(int i = 0; i < tot; i++) { node t = q[i]; while(timer < t.timer) { timer++; modify(chg[timer].x, chg[timer].val); } while(timer > t.timer) { modify(chg[timer].x, chg[timer].last); timer--; } while(r < t.r) add(++r); while(l > t.l) add(--l); while(r > t.r) sub(r--); while(l < t.l) sub(l++); for(int j = 1; j <= up; j++) if(se[j] == 0) { an[t.id] = j; break; } } for(int i = 0; i < tot; i++) { printf("%d\n", an[i]); } }
return 0; }
|