#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
const int arr = 2e5 + 10;
const int ar = 2e3 + 10;
const long double pi = acos(-1);
const long double eps = 1e-10;
const long long md = 1e9 + 7;
const int __BS = 4096;
static char __bur[__BS + 16], *__er = __bur + __BS, *__ir = __er;
template <class T = int>
T read_int() {
  auto c = [&]() {
    if (__ir == __er)
      std::fill(__bur, __bur + __BS, 0), cin.read(__bur, __BS), __ir = __bur;
  };
  c();
  while (*__ir && (*__ir < '0' || *__ir > '9') && *__ir != '-') ++__ir;
  c();
  bool m = false;
  if (*__ir == '-') ++__ir, c(), m = true;
  T r = 0;
  while (*__ir >= '0' && *__ir <= '9') r = r * 10 + *__ir - '0', ++__ir, c();
  ++__ir;
  return m ? -r : r;
}
int a[arr];
int main() {
  int n, m;
  n = read_int();
  m = read_int();
  for (int i = 1; i <= n; i++) {
    a[i] = read_int();
  }
  while (m--) {
    int type, l, r, x;
    type = read_int();
    l = read_int();
    r = read_int();
    x = read_int();
    int* ap = a + l;
    r -= l;
    r++;
    if (type == 1) {
      for (int i = 0; i < r; i++) {
        ap[i] -= (ap[i] > x ? x : 0);
      }
    } else {
      int ans = 0;
      for (int i = 0; i < r; i++) {
        ans += (ap[i] == x);
      }
      cout << ans << "\n";
    }
  }
}
