#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("avx")
#pragma GCC diagnostic ignored "-Wunused-result"
float __attribute__((aligned(32))) a[100010];
inline int read() {
  int x = 0;
  char ch;
  for (ch = getchar(); ch < '0' || ch > '9'; ch = getchar())
    ;
  for (; ch >= '0' && ch <= '9';
       x = (x << 3) + (x << 1) + ch - '0', ch = getchar())
    ;
  return x;
}
int main() {
  int n, m;
  n = read();
  m = read();
  for (register int i = 1; i <= n; ++i) a[i] = read();
  int ty, l, r, x, A;
  while (m--) {
    ty = read();
    l = read();
    r = read();
    x = read();
    if (ty == 1)
      for (register int i = l; i <= r; ++i) a[i] -= (a[i] > x ? x : 0);
    else {
      A = 0;
      for (register int i = l; i <= r; ++i)
        if (a[i] == x) ++A;
      printf("%d\n", A);
    }
  }
  return 0;
}
