#include <bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
const int N = 1e5 + 5, INF = 0x3f3f3f3f;
inline int read() {
  int x = 0, f = 0;
  char ch = 0;
  while (!isdigit(ch)) f |= ch == '-', ch = getchar();
  while (isdigit(ch)) x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar();
  return f ? -x : x;
}
int a[N];
int main() {
  int n = read(), m = read();
  for (int i = 1; i <= n; ++i) a[i] = read();
  int opt, l, r, x, i, ans;
  for (int j = 1; j <= m; ++j) {
    opt = read(), l = read(), r = read(), x = read();
    if (opt == 1) {
      for (i = l; i + 4 <= r; i += 8) {
        a[i] -= (a[i] > x ? x : 0);
        a[i + 1] -= (a[i + 1] > x ? x : 0);
        a[i + 2] -= (a[i + 2] > x ? x : 0);
        a[i + 3] -= (a[i + 3] > x ? x : 0);
        a[i + 4] -= (a[i + 4] > x ? x : 0);
      }
      for (; i <= r; ++i) a[i] -= (a[i] > x) * x;
    } else {
      ans = 0;
      for (i = l; i + 4 <= r; i += 8)
        ans += (a[i] == x) + (a[i + 1] == x) + (a[i + 2] == x) +
               (a[i + 3] == x) + (a[i + 4] == x);
      for (; i <= r; ++i) ans += (a[i] == x);
      printf("%d\n", ans);
    }
  }
  return 0;
}
