#include <bits/stdc++.h>
#pragma GCC optimize( \
    "Ofast,unroll-loops,no-stack-protector,unsafe-math-optimizations")
#pragma GCC target("avx")
int fastscan() {
  bool negative = false;
  register int c;
  int number = 0;
  c = getchar();
  if (c == '-') {
    negative = true;
    c = getchar();
  }
  for (; (c > 47 && c < 58); c = getchar()) number = number * 10 + c - 48;
  if (negative) number *= -1;
  return number;
}
float __attribute__((aligned(64))) a[100005];
int n, m, ans, t, l, r;
float x;
int main() {
  n = fastscan();
  m = fastscan();
  for (int i = 1; i <= n; i++) a[i] = fastscan();
  for (int i = 1; i <= m; i++) {
    t = fastscan();
    l = fastscan();
    r = fastscan();
    x = fastscan();
    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);
    }
  }
}
