#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 79, maxn2 = (1 << 17);
vector<vector<long long> > f(maxn2 * 2);
vector<vector<int> > s(maxn2 * 2);
vector<set<int> > oc(maxn);
int pv(int e, int l) { return *(--oc[e].lower_bound(l)); }
int nx(int e, int l) { return *oc[e].upper_bound(l); }
vector<array<int, 3> > qu(maxn);
vector<int> a(maxn), l(maxn2 * 2), r(maxn2 * 2);
void add(int vr, int i, long long d) {
  for (; i >= 0; i = (i & (i + 1)) - 1) f[vr][i] += d;
}
long long sum(int vr, int i) {
  long long rval = 0;
  for (; i < f[vr].size(); i = (i | (i + 1))) rval += f[vr][i];
  return rval;
}
void insert_pos(int i, int p, int vr = 0) {
  s[vr].push_back(p);
  if (l[vr] < r[vr])
    insert_pos(i, p, i < l[vr * 2 + 2] ? vr * 2 + 1 : vr * 2 + 2);
}
void update(int i, int p, long long val, int vr = 0) {
  add(vr, lower_bound(s[vr].begin(), s[vr].end(), p) - s[vr].begin(),
      (i - p) * val);
  if (l[vr] < r[vr])
    update(i, p, val, i < l[vr * 2 + 2] ? vr * 2 + 1 : vr * 2 + 2);
}
long long query(int li, int ri, int vr = 0) {
  if (ri < l[vr] || li > r[vr]) return 0;
  if (li <= l[vr] && r[vr] <= ri) {
    int id = lower_bound(s[vr].begin(), s[vr].end(), li) - s[vr].begin();
    return sum(vr, id);
  }
  return query(li, ri, vr * 2 + 1) + query(li, ri, vr * 2 + 2);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, q;
  cin >> n >> q;
  for (int i = maxn2 - 1; i < maxn2 * 2; i++) l[i] = r[i] = i - (maxn2 - 1);
  for (int i = maxn2 - 2; i >= 0; i--) l[i] = l[i * 2 + 1], r[i] = r[i * 2 + 2];
  for (int i = 0; i <= n; i++) oc[i] = {-1, n};
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    oc[a[i]].insert(i);
  }
  for (int i = 1; i <= n; i++)
    for (int j : oc[i])
      if (j != *oc[i].begin()) insert_pos(j, pv(i, j));
  vector<int> a2 = a;
  for (int i = 0; i < q; i++) {
    cin >> qu[i][0] >> qu[i][1] >> qu[i][2];
    if (qu[i][0] == 2) continue;
    int in = qu[i][1] - 1, x = qu[i][2], pvx = a2[qu[i][1] - 1];
    insert_pos(in, pv(pvx, in)), insert_pos(nx(pvx, in), in);
    oc[pvx].erase(in);
    insert_pos(nx(pvx, in), pv(pvx, in));
    a2[in] = x;
    insert_pos(nx(x, in), pv(x, in));
    oc[x].insert(in);
    insert_pos(in, pv(x, in)), insert_pos(nx(x, in), in);
  }
  for (int i = 0; i < maxn2 * 2; i++) {
    sort(s[i].begin(), s[i].end());
    s[i].erase(unique(s[i].begin(), s[i].end()), s[i].end());
    f[i].resize(s[i].size() + 1, 0);
  }
  oc.assign(n + 1, set<int>());
  for (int i = 0; i <= n; i++) oc[i] = {-1, n};
  for (int i = 0; i < n; i++) {
    oc[a[i]].insert(i);
    update(i, pv(a[i], i), 1);
  }
  for (int i = 0; i < q; i++) {
    if (qu[i][0] == 2) {
      cout << query(qu[i][1] - 1, qu[i][2] - 1) << "\n";
      continue;
    }
    int in = qu[i][1] - 1, x = qu[i][2], pvx = a[qu[i][1] - 1];
    update(in, pv(pvx, in), -1), update(nx(pvx, in), in, -1);
    oc[pvx].erase(in);
    update(nx(pvx, in), pv(pvx, in), 1);
    a[in] = x;
    update(nx(x, in), pv(x, in), -1);
    oc[x].insert(in);
    update(in, pv(x, in), 1), update(nx(x, in), in, 1);
  }
  return 0;
}
