#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize( \
    "Ofast,unroll-loops,no-stack-protector,unsafe-math-optimizations")
#pragma GCC target("avx")
const int BUFFER_MAX_SIZE = 100000;
struct Quick_In {
  char buf[BUFFER_MAX_SIZE], *ps = buf, *pe = buf + 1;
  inline void InNext() {
    if (++ps == pe)
      pe = (ps = buf) +
           fread(buf, sizeof(char), sizeof(buf) / sizeof(char), stdin);
  }
  template <class T>
  inline bool operator()(T &number) {
    number = 0;
    T f = 1;
    bool vis_point = 0;
    if (ps == pe) return false;
    do {
      InNext();
      if ('-' == *ps) f = -1;
    } while (ps != pe && !isdigit(*ps));
    if (ps == pe) return false;
    do {
      if ((*ps) == '.')
        vis_point = 1;
      else {
        number = number * 10 + *ps - 48;
        if (vis_point) f *= 0.1;
      }
      InNext();
    } while (ps != pe && (isdigit(*ps) || (*ps) == '.'));
    number *= f;
    return true;
  }
} In;
struct Quick_Out {
  char buf[BUFFER_MAX_SIZE], *ps = buf, *pe = buf + BUFFER_MAX_SIZE;
  char tmp[100];
  double dx[15] = {5e-1, 5e-2,  5e-3,  5e-4,  5e-5,  5e-6,  5e-7, 5e-8,
                   5e-9, 5e-10, 5e-11, 5e-12, 5e-13, 5e-14, 5e-15};
  inline void write() {
    fwrite(buf, sizeof(char), ps - buf, stdout);
    ps = buf;
  }
  inline void oc(char c) {
    *(ps++) = c;
    if (ps == pe) write();
  }
  inline void os(char *s) {
    for (int i = 0; s[i]; ++i) oc(s[i]);
  }
  template <class T>
  inline void oi(T x, char bc = '\n') {
    if (x < 0) oc('-'), x = -x;
    int len = 0;
    if (!x) tmp[len++] = '0';
    while (x) tmp[len++] = x % 10 + '0', x /= 10;
    while (len) oc(tmp[--len]);
    oc(bc);
  }
  ~Quick_Out() { write(); }
} Out;
const int maxn = 1e5 + 5;
int a[maxn];
int main() {
  int n, m, i, op, l, r, x, u;
  In(n);
  In(m);
  for (i = 1; i <= n; i++) In(a[i]);
  while (m--) {
    In(op);
    In(l);
    In(r);
    In(x);
    if (op == 1) {
      for (i = l; i <= r; i++) {
        if (a[i] > x) a[i] -= x;
      }
    } else {
      u = 0;
      for (i = l; i <= r; i++) u += a[i] == x;
      Out.oi(u);
    }
  }
  return 0;
}
