#include <bits/stdc++.h>
using namespace std;
const int B = 316;
const int S = (101000 / B) + 1;
int N, Q;
int A[100000];
int X[S][100000];
int W[S];
int find(int b, int x) {
  if (x >= W[b] || X[b][x] == x) return x;
  return X[b][x] = find(b, X[b][x]);
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> N >> Q;
  for (int i = 0; i < (N); i++) cin >> A[i], A[i]--;
  for (int i = 0; i < (N); i++) X[i / B][A[i]]++;
  for (int i = 0; i < (Q); i++) {
    int t, l, r, x;
    cin >> t >> l >> r >> x;
    l--, r--;
    int lb = (l + B - 1) / B, rb = r / B - 1;
    if (t == 1) {
      if (lb > rb) {
        for (int i = l; i <= r; i++) {
          int a = find(i / B, A[i]);
          if (a - W[i / B] < x) continue;
          X[i / B][a]--;
          a -= x;
          A[i] = a;
          X[i / B][a]++;
        }
      } else {
        for (int i = l; i < lb * B; i++) {
          int a = find(i / B, A[i]);
          if (a - W[i / B] < x) continue;
          X[i / B][a]--;
          a -= x;
          A[i] = a;
          X[i / B][a]++;
        }
        for (int i = (rb + 1) * B; i <= r; i++) {
          int a = find(i / B, A[i]);
          if (a - W[i / B] < x) continue;
          X[i / B][a]--;
          a -= x;
          A[i] = a;
          X[i / B][a]++;
        }
        for (int b = lb; b <= rb; b++) {
          int w = W[b];
          for (int _ = 0; _ < (x); _++) {
            if (w >= 100000) break;
            if (w + x < 100000) X[b][w + x] += X[b][w];
            if (w + x < 100000)
              X[b][w] = w + x;
            else
              X[b][w] = w;
            w++;
          }
          W[b] = w;
        }
      }
    } else {
      x--;
      int s = 0;
      if (lb > rb) {
        for (int i = l; i <= r; i++)
          if (find(i / B, A[i]) - W[i / B] == x) s++;
      } else {
        for (int i = l; i < lb * B; i++)
          if (find(i / B, A[i]) - W[i / B] == x) s++;
        for (int b = lb; b <= rb; b++)
          if (x + W[b] < 100000) s += X[b][x + W[b]];
        for (int i = (rb + 1) * B; i <= r; i++)
          if (find(i / B, A[i]) - W[i / B] == x) s++;
      }
      cout << s << "\n";
    }
  }
  return 0;
}
