#include <bits/stdc++.h>
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2")
using namespace std;
const int mn = 100005;
char buf[10000000], *p1 = buf, *p2 = buf;
void in(int &r) {
  static char c;
  r = 0;
  while (c = p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 10000000, stdin),
                          p1 == p2)
                 ? EOF
                 : *p1++,
         c < 48)
    ;
  do r = (r << 1) + (r << 3) + (c ^ 48);
  while (c = p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 10000000, stdin),
                          p1 == p2)
                 ? EOF
                 : *p1++,
         c > 47);
}
int val[mn], n, m, ty, l, r, v;
int main() {
  in(n), in(m);
  for (int q = 1, q_end_ = n; q <= q_end_; ++q) in(val[q]);
  register int w, ans;
  for (int q = 1, q_end_ = m; q <= q_end_; ++q) {
    in(ty), in(w), in(r), in(v);
    if (ty == 1) {
      for (; w <= r; ++w) val[w] -= val[w] > v ? v : 0;
    } else {
      ans = 0;
      for (; w <= r; ++w) ans += val[w] == v;
      printf("%d\n", ans);
    }
  }
  return 0;
}
