#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#pragma GCC target( \
    "sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,avx2,popcnt,tune=native")
#pragma GCC optimize("inline", "fast-math", "unroll-loops", \
                     "no-stack-protector")
using namespace std;
const int N = 100005;
int n, m;
int a[N];
int li = 0;
int l, r, x, opt, j, cnt = 0;
bool flag = 1;
bool flag2 = 0;
int ans = 0;
int pnt = 0;
int ans0 = 0, ans1 = 0, ans2 = 0, ans3 = 0, ans4 = 0, ans5 = 0, ans6 = 0,
    ans7 = 0;
int Opt[N], L[N], R[N], X[N];
int bot[N];
inline int read() {
  int res = 0, ch, flag = 0;
  if ((ch = getchar()) == '-')
    flag = 1;
  else if (ch >= '0' && ch <= '9')
    res = ch - '0';
  while ((ch = getchar()) >= '0' && ch <= '9') res = res * 10 + ch - '0';
  return flag ? -res : res;
}
inline void Write(int a) {
  if (a > 9) Write(a / 10);
  putchar(a % 10 + '0');
}
int main() {
  n = read(), m = read();
  for (register int i = 1; i <= n; ++i) {
    a[i] = read();
    if (i > 1 && a[i] != a[i - 1]) flag2 = 1;
    bot[a[i]]++;
  }
  for (register int i = 1; i <= m; i++) {
    Opt[i] = read(), L[i] = read(), R[i] = read(), X[i] = read(),
    li += Opt[i] - 1;
    if (L[i] != 1 || R[i] != n) flag2 = 1;
  }
  if (!flag2) {
    int lst = a[1];
    for (register int i = 1; i <= m; ++i) {
      opt = Opt[i], l = L[i], r = R[i], x = X[i];
      if (opt == 1) {
        bot[x] = bot[lst];
        bot[lst] = 0;
        lst = x;
      } else {
        Write(bot[x]);
        putchar('\n');
      }
    }
    return 0;
  }
  for (register int i = 1; i <= m; ++i) {
    opt = Opt[i], l = L[i], r = R[i], x = X[i];
    if (opt == 1) {
      flag = 1;
      for (j = l; j + 8 <= r; j += 8) {
        a[j] -= (a[j] > x) ? x : 0;
        a[j + 1] -= (a[j + 1] > x) ? x : 0;
        a[j + 2] -= (a[j + 2] > x) ? x : 0;
        a[j + 3] -= (a[j + 3] > x) ? x : 0;
        a[j + 4] -= (a[j + 4] > x) ? x : 0;
        a[j + 5] -= (a[j + 5] > x) ? x : 0;
        a[j + 6] -= (a[j + 6] > x) ? x : 0;
        a[j + 7] -= (a[j + 7] > x) ? x : 0;
      }
      for (; j <= r; ++j) a[j] -= (a[j] > x) ? x : 0;
    } else if (flag == 0 && L[i] == L[i - 1] && R[i] == R[i - 1] &&
               X[i] == X[i - 1]) {
      Write(ans);
      putchar('\n');
    } else {
      flag = 0;
      ++cnt;
      ans0 = 0;
      ans1 = 0;
      ans2 = 0;
      ans3 = 0;
      ans4 = 0;
      ans5 = 0;
      ans6 = 0;
      ans7 = 0;
      for (j = l - 1; j + 8 <= r; j += 8) {
        ans1 += (a[j + 1] == x) ? 1 : 0;
        ans2 += (a[j + 2] == x) ? 1 : 0;
        ans3 += (a[j + 3] == x) ? 1 : 0;
        ans4 += (a[j + 4] == x) ? 1 : 0;
        ans5 += (a[j + 5] == x) ? 1 : 0;
        ans6 += (a[j + 6] == x) ? 1 : 0;
        ans7 += (a[j + 7] == x) ? 1 : 0;
        ans0 += (a[j + 8] == x) ? 1 : 0;
      }
      switch ((r - l + 1) & 7) {
        case 7:
          ans6 += (a[r - 6] == x) ? 1 : 0;
        case 6:
          ans5 += (a[r - 5] == x) ? 1 : 0;
        case 5:
          ans4 += (a[r - 4] == x) ? 1 : 0;
        case 4:
          ans3 += (a[r - 3] == x) ? 1 : 0;
        case 3:
          ans2 += (a[r - 2] == x) ? 1 : 0;
        case 2:
          ans1 += (a[r - 1] == x) ? 1 : 0;
        case 1:
          ans0 += (a[r] == x) ? 1 : 0;
      }
      ans = ans0 + ans1 + ans2 + ans3 + ans4 + ans5 + ans6 + ans7;
      Write(ans);
      putchar('\n');
    }
  }
  return 0;
}
