#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
int n, m, a[110000];
float x, p;
static char buf[1000000], *p1 = buf, *p2 = buf;
inline char gc() {
  return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin), p1 == p2)
             ? -1
             : *p1++;
}
inline int read() {
  register int x = 0;
  register char a = gc();
  while (a < '0' || a > '9') a = gc();
  while (a >= '0' && a <= '9') x = (x << 1) + (x << 3) + (a ^ 48), a = gc();
  return x;
}
int main() {
  n = read();
  m = read();
  for (register int i = 1; i <= n; i++) a[i] = read();
  while (m--) {
    register int opt, l, r, ans = 0;
    opt = read();
    l = read();
    r = read();
    x = read();
    if (opt & 1)
      for (register int i = l; i <= r; i++) a[i] -= (a[i] > x) ? x : 0;
    else {
      for (register int i = l; i <= r; i++) ans += !(a[i] - x);
      printf("%d\n", ans);
    }
  }
}
