#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
int a[100005];
inline int read() {
  int x = 0;
  char c = getchar();
  while (c < '0' || c > '9') c = getchar();
  while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
  return x;
}
int main() {
  int opt, l, r, x, i, j, cnt, n, m;
  n = read();
  m = read();
  for (i = 1; i <= n; i++) {
    a[i] = read();
  }
  for (i = 1; i <= m; i++) {
    opt = read();
    l = read();
    r = read();
    x = read();
    if (opt == 1) {
      int tms = (r - l + 1) / 4;
      int d = (r - l + 1) % 4;
      while (d--) {
        if (a[l] > x) a[l] -= x;
        l++;
      }
      auto ap = a + l;
      while (tms--) {
        ap[0] -= ap[0] > x ? x : 0;
        ap[1] -= ap[1] > x ? x : 0;
        ap[2] -= ap[2] > x ? x : 0;
        ap[3] -= ap[3] > x ? x : 0;
        ap += 4;
      }
    } else {
      int tms = (r - l + 1) / 4;
      int d = (r - l + 1) % 4;
      cnt = 0;
      while (d--) cnt += (a[l++] == x);
      auto ap = a + l;
      while (tms--) {
        cnt += (ap[0] == x) + (ap[1] == x) + (ap[2] == x) + (ap[3] == x);
        ap += 4;
      }
      printf("%d\n", cnt);
    }
  }
  return 0;
}
