func_code_string: #include <bits/stdc++.h>   using namespace std;   const long long N = 100009;   struct query {     long long a, b, op, s;   } q[N * 9], b[N * 9];   long long n, m, a[N], ans[N], cnt, cntq, tr[N];   set<long long> Set[N];   inline void add(long long x, long long c) {     while (x <= n) {       tr[x] += c, x += (x & -x);     }   }   inline long long ask(long long x) {     long long res = 0;     while (x) {       res += tr[x], x -= (x & -x);     }     return res;   }   inline bool cmp(query x, query y) {     if (x.op != y.op)       return x.op < y.op;     else if (x.op)       return x.a < y.a;     else       return x.b < y.b;   }   void cdq(long long l, long long r) {     if (l >= r) return;     long long mid = (l + r) >> 1;     cdq(l, mid), cdq(mid + 1, r);     long long p1 = l, p2 = mid + 1, Cnt = l;     for (long long i = mid + 1; i <= r; i++)       if (q[i].op) {         while (p1 <= mid && (q[p1].b <= q[i].b)) {           if (!q[p1].op) add(q[p1].a, (q[p1].s * (q[p1].b - q[p1].a)));           p1++;         }         ans[q[i].op] += ask(n) - ask(q[i].a - 1);       }     for (long long i = l; i < p1; i++)       if (!q[i].op) add(q[i].a, -(q[i].s * (q[i].b - q[i].a)));     for (long long k = l, i = l, j = mid + 1; k <= r; k++)       b[k] = (j > r || (i <= mid && q[i].b <= q[j].b)) ? q[i++] : q[j++];     for (long long i = l; i <= r; i++) q[i] = b[i];   }   signed main() {     scanf( %lld%lld , &n, &m);     for (long long i = 1; i <= n; i++) {       scanf( %lld , &a[i]);       Set[a[i]].insert(i);       if (Set[a[i]].size() != 1) q[++cnt] = {*(--Set[a[i]].rbegin()), i, 0, 1};     }     for (long long i = 1; i <= m; i++) {       long long op, b, c, l = 0, r = 0;       scanf( %lld%lld%lld , &op, &b, &c);       if (op == 2) {         q[++cnt] = {b, c, ++cntq, 0};       } else {         set<long long>::iterator i = Set[a[b]].find(b);         if (i != Set[a[b]].begin()) {           l = *--i;           q[++cnt] = {l, b, 0, -1};           i++;         }         if (++i != Set[a[b]].end()) {           r = *i;           q[++cnt] = {b, r, 0, -1};         }         if (l && r) q[++cnt] = {l, r, 0, 1};         Set[a[b]].erase(b);         Set[c].insert(b);         l = r = 0;         i = Set[c].find(b);         a[b] = c;         if (i != Set[c].begin()) {           l = *--i;           q[++cnt] = {l, b, 0, 1};           i++;         }         if (++i != Set[c].end()) {           r = *i;           q[++cnt] = {b, r, 0, 1};         }         if (l && r) q[++cnt] = {l, r, 0, -1};       }     }     cdq(1, cnt);     for (long long i = 1; i <= cntq; i++) printf( %lld n , ans[i]);     return 0;   }   