#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")
using namespace std;
int m, n;
int p[1000005];
static char buf[1000000];
static char *st = buf, *ed = buf;
inline char getc(void) {
  return st == ed && (ed = (st = buf) + fread(buf, 1, 1000000, stdin), st == ed)
             ? EOF
             : *st++;
}
inline int read(void) {
  register int x = 0;
  register char c = getc();
  while (c < '0' || c > '9') {
    c = getc();
  }
  while (c >= '0' && c <= '9') {
    x = (x << 1) + (x << 3) + (c ^ 48);
    c = getc();
  }
  return x;
}
int main() {
  n = read();
  m = read();
  for (register int i = 1; i <= n; i++) {
    p[i] = read();
  }
  register int l, r, op, x, cnt;
  while (m--) {
    op = read();
    l = read();
    r = read();
    x = read();
    cnt = 0;
    if (op == 1) {
      while (l <= r) {
        p[l] -= (p[l] > x) ? x : 0;
        l++;
      }
    } else {
      while (l <= r) {
        cnt += !(p[l] - x);
        l++;
      }
      printf("%d\n", cnt);
    }
  }
  return 0;
}
