#include <bits/stdc++.h>
using namespace std;
int n, m, a[100010], pos[100010], pre[100010], nxt[100010];
struct node {
  long long s;
  node *lc, *rc;
  node() { s = 0; }
} t[10000010], *root[100010], *tail = t;
template <class Aqua>
inline void read(Aqua &s) {
  s = 0;
  char c = getchar();
  while (!isdigit(c)) c = getchar();
  while (isdigit(c)) s = s * 10 + c - '0', c = getchar();
}
void prep() {
  for (int i = 1; i <= n; i++) root[i] = t;
  t->lc = t->rc = t;
}
void modify(node *&cur, int l, int r, int pos, int d) {
  if (cur == t) cur = ++tail, cur->lc = cur->rc = t;
  if (l == r) {
    cur->s += d;
    return;
  }
  if (pos <= ((l + r) >> 1))
    modify(cur->lc, l, ((l + r) >> 1), pos, d);
  else
    modify(cur->rc, ((l + r) >> 1) + 1, r, pos, d);
  cur->s = cur->lc->s + cur->rc->s;
}
long long query(node *cur, int l, int r, int L, int R) {
  if (L <= l && r <= R) {
    return cur->s;
  }
  long long ans = 0;
  if (L <= ((l + r) >> 1)) ans += query(cur->lc, l, ((l + r) >> 1), L, R);
  if (R > ((l + r) >> 1)) ans += query(cur->rc, ((l + r) >> 1) + 1, r, L, R);
  return ans;
}
void Modify(int x, int y, int d) {
  if (!x) return;
  for (int i = x; i <= n; i += i & (-i)) modify(root[i], 1, n, y, d);
}
long long Query(int x, int y) {
  long long ans = 0;
  for (int i = x; i; i &= (i - 1)) ans += query(root[i], 1, n, y, n);
  return ans;
}
set<int> ind[100010];
set<int>::iterator it;
void adjust(int pos, int d) {
  if (a[pos] == d) return;
  if (nxt[pos]) {
    Modify(nxt[pos], pos, pos - nxt[pos]);
    if (pre[pos] == pos)
      pre[nxt[pos]] = nxt[pos];
    else
      pre[nxt[pos]] = pre[pos];
    Modify(nxt[pos], pre[nxt[pos]], nxt[pos] - pre[nxt[pos]]);
  }
  nxt[pre[pos]] = nxt[pos];
  Modify(pos, pre[pos], pre[pos] - pos);
  ind[a[pos]].erase(pos);
  it = ind[d].upper_bound(pos);
  if (it == ind[d].end())
    nxt[pos] = 0;
  else
    nxt[pos] = *it, pre[nxt[pos]] = pos, Modify(nxt[pos], pos, nxt[pos] - pos);
  if (it == ind[d].begin())
    pre[pos] = pos;
  else
    pre[pos] = *(--it), nxt[pre[pos]] = pos;
  Modify(pos, pre[pos], pos - pre[pos]);
  if (pre[pos] != pos && nxt[pos])
    Modify(nxt[pos], pre[pos], pre[pos] - nxt[pos]);
  ind[d].insert(pos);
  a[pos] = d;
}
int main() {
  read(n), read(m);
  for (int i = 1; i <= n; i++) read(a[i]);
  prep();
  for (int i = 1; i <= n; i++) {
    if (pos[a[i]] == 0) pos[a[i]] = i;
    Modify(i, pos[a[i]], i - pos[a[i]]);
    pre[i] = pos[a[i]];
    if (pos[a[i]] != i) nxt[pos[a[i]]] = i;
    pos[a[i]] = i;
    ind[a[i]].insert(i);
  }
  int opt, x, y;
  for (int i = 1; i <= m; i++) {
    read(opt), read(x), read(y);
    if (opt == 1)
      adjust(x, y);
    else
      printf("%lld\n", Query(y, x));
  }
  return 0;
}
