#include <bits/stdc++.h>
#pragma GCC optimize( \
    "Ofast,unroll-loops,no-stack-protector,unsafe-math-optimizations")
#pragma GCC target("avx")
using namespace std;
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);
}
inline void writeInt(int n) {
  int N = n, rev, count = 0;
  rev = N;
  if (N == 0) {
    putchar('0');
    ;
    putchar('\n');
    ;
    return;
  }
  while ((rev % 10) == 0) {
    count++;
    rev /= 10;
  }
  rev = 0;
  while (N != 0) {
    rev = (rev << 3) + (rev << 1) + N % 10;
    N /= 10;
  }
  while (rev != 0) {
    putchar(rev % 10 + '0');
    ;
    rev /= 10;
  }
  while (count--) putchar('0');
  ;
  putchar('\n');
  ;
}
float __attribute__((aligned(64))) a[100005], x;
int n, m, t, l, r;
int ans;
int main() {
  n = read_int();
  m = read_int();
  for (int i = 1; i <= n; i++) a[i] = read_int();
  for (int i = 0; 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++) a[j] -= a[j] > x ? x : 0;
    } else {
      ans = 0;
      for (int j = l; j <= r; j++) ans += (a[j] == x);
      writeInt(ans);
    }
  }
}
