#include <bits/stdc++.h>
using namespace std;
namespace acheing {
set<int> s1[110000], s2[110000];
int i, j, k, n, m, x, y, t, num, a[110000], ti, v[110000];
bool b[110000], c[110000];
struct data {
  int x, y, id, k, p, ansid;
} w[1000010], ask[110000], mark[1000010];
long long ans[1000010], s[110000];
int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    f = ch == '-' ? -f : f;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - 48;
    ch = getchar();
  }
  return x * f;
}
void init() {
  scanf("%d%d", &n, &m);
  for (i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (i = 1; i <= m; i++) {
    scanf("%d%d%d", &ask[i].k, &ask[i].x, &ask[i].y);
    ask[i].id = i;
  }
}
bool cmp(const data& a, const data& b) {
  return a.x == b.x ? (a.y == b.y ? a.id < b.id : a.y < b.y) : a.x > b.x;
}
void pre() {
  for (i = 1; i <= n; i++) {
    x = -*s2[a[i]].lower_bound(-i);
    if (x != 0) {
      w[++num].x = x;
      w[num].y = i;
      w[num].id = num;
      w[num].k = 1;
      w[num].p = i - x;
    }
    s1[a[i]].insert(i);
    s2[a[i]].insert(-i);
    if (!c[a[i]]) {
      s1[a[i]].insert(n + 10);
      s2[a[i]].insert(0);
      c[a[i]] = 1;
    }
  }
  for (i = 1; i <= m; i++) {
    if (ask[i].k == 1) {
      if (!c[ask[i].y]) {
        s1[ask[i].y].insert(n + 10);
        s2[ask[i].y].insert(0);
        c[ask[i].y] = 1;
      }
      x = *s1[a[ask[i].x]].lower_bound(ask[i].x + 1),
      y = -*s2[a[ask[i].x]].lower_bound(-ask[i].x + 1);
      if (y) {
        w[++num].x = y;
        w[num].y = ask[i].x;
        w[num].p = -(ask[i].x - y);
        w[num].k = 1;
        w[num].id = num;
      }
      if (x != n + 10) {
        w[++num].x = ask[i].x;
        w[num].y = x;
        w[num].p = -(x - ask[i].x);
        w[num].k = 1;
        w[num].id = num;
      }
      if (x != n + 10 && y) {
        w[++num].x = y;
        w[num].y = x;
        w[num].p = (x - y);
        w[num].k = 1;
        w[num].id = num;
      }
      s1[a[ask[i].x]].erase(ask[i].x);
      s2[a[ask[i].x]].erase(-ask[i].x);
      x = *s1[ask[i].y].lower_bound(ask[i].x + 1),
      y = -*s2[ask[i].y].lower_bound(-ask[i].x + 1);
      if (y) {
        w[++num].x = y;
        w[num].y = ask[i].x;
        w[num].p = (ask[i].x - y);
        w[num].k = 1;
        w[num].id = num;
      }
      if (x != n + 10) {
        w[++num].x = ask[i].x;
        w[num].y = x;
        w[num].p = (x - ask[i].x);
        w[num].k = 1;
        w[num].id = num;
      }
      if (x != n + 10 && y) {
        w[++num].x = y;
        w[num].y = x;
        w[num].p = -(x - y);
        w[num].k = 1;
        w[num].id = num;
      }
      s1[ask[i].y].insert(ask[i].x);
      s2[ask[i].y].insert(-ask[i].x);
      a[ask[i].x] = ask[i].y;
    } else {
      w[++num].x = ask[i].x;
      w[num].y = ask[i].y;
      w[num].k = 2;
      w[num].id = num;
      w[num].ansid = i;
      b[i] = 1;
    }
  }
  sort(w + 1, w + 1 + num, cmp);
}
void update(int x, int y) {
  int t = x;
  while (t <= n) {
    if (v[t] != ti) s[t] = 0, v[t] = ti;
    s[t] += y;
    t += t & -t;
  }
}
int query(int x) {
  int t = x, ans = 0;
  while (t) {
    if (v[t] != ti) s[t] = 0, v[t] = ti;
    ans += s[t];
    t -= t & -t;
  }
  return ans;
}
void cdq(int l, int r) {
  if (l >= r) return;
  int mid = (l + r) >> 1;
  int x = l, y = mid + 1;
  ti++;
  for (int i = l; i <= r; i++)
    if (w[i].id <= mid) {
      mark[x++] = w[i];
      if (w[i].k == 1) update(w[i].y, w[i].p);
    } else {
      if (w[i].k == 2) ans[w[i].ansid] += query(w[i].y);
      mark[y++] = w[i];
    }
  for (int i = l; i <= r; i++) w[i] = mark[i];
  cdq(l, mid);
  cdq(mid + 1, r);
}
void work() {
  pre();
  cdq(1, num);
  for (i = 1; i <= m; i++)
    if (b[i]) printf("%lld\n", ans[i]);
  return;
}
void main() {
  init();
  work();
  return;
}
}  // namespace acheing
int main() {
  acheing::main();
  return 0;
}
