#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")
static int a[100001], n, m, l, r, x, cnt;
static bool type;
inline static int read() {
  register int x = 0;
  static char ch = getchar();
  while (ch < '0' || ch > '9') ch = getchar();
  while (ch >= '0' && ch <= '9')
    x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
  return x;
}
signed main(void) {
  n = read(), m = read();
  for (register int i = 1; i <= n; ++i) a[i] = read();
  for (; m--;) {
    type = (read() == 1);
    l = read(), r = read(), x = read();
    if (type)
      for (register int i = l; i <= r; ++i) a[i] -= (a[i] > x) ? x : 0;
    else {
      cnt = 0;
      for (register int i = l; i <= r; ++i) cnt += (a[i] == x);
      printf("%d\n", cnt);
    }
  }
}
