#include <bits/stdc++.h>
#pragma GCC optimize( \
    "Ofast,unroll-loops,no-stack-protector,unsafe-math-optimizations")
#pragma GCC target("avx")
inline int read_char() {
  static char buf[1 << 16], *ptr = buf, *end_ptr = buf;
  if (ptr == end_ptr) {
    int len = fread(buf, 1, sizeof(buf), stdin);
    if (len <= 0) return EOF;
    ptr = buf;
    end_ptr = buf + len;
  }
  return *ptr++;
}
inline int read_int() {
  int ch;
  bool sg = 0;
  do {
    ch = read_char();
    if (ch == '-') sg = 1;
  } while (ch < '0' || ch > '9');
  int x = ch - '0';
  while (true) {
    ch = read_char();
    if (ch < '0' || ch > '9') break;
    x = x * 10 + ch - '0';
  }
  return (sg ? -x : x);
}
float __attribute__((aligned(64))) a[1 << 17];
int n, m, ans, t, l, r;
float x;
int main() {
  n = read_int();
  m = read_int();
  for (int i = 1; i <= n; i++) a[i] = read_int();
  for (int i = 1; i <= m; i++) {
    t = read_int();
    l = read_int();
    r = read_int();
    x = read_int();
    if (t == 1) {
      for (int j = l; j <= r; j++)
        if (a[j] > x) a[j] -= x;
    } else {
      ans = 0;
      for (int j = l; j <= r; j++) ans += (a[j] == x);
      printf("%d\n", ans);
    }
  }
}
