#include <bits/stdc++.h>
using namespace std;
const int oo = 2139063143;
const int N = 500100;
const int P = 1000000007;
const double eps = 1e-7;
char buf[1 << 20 | 1], *p1 = buf, *p2 = buf, obuf[1 << 20 | 1], *O = obuf;
template <typename T>
inline void sc(T &x) {
  x = 0;
  static int p;
  p = 1;
  static char c;
  c = (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 20, stdin), p1 == p2)
           ? EOF
           : *p1++);
  while (!isdigit(c)) {
    if (c == '-') p = -1;
    c = (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 20, stdin), p1 == p2)
             ? EOF
             : *p1++);
  }
  while (isdigit(c)) {
    x = (x << 1) + (x << 3) + (c - 48);
    c = (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 20, stdin), p1 == p2)
             ? EOF
             : *p1++);
  }
  x *= p;
}
template <typename T>
inline void print(T x) {
  if (x < 0) putchar('-'), x = -x;
  if (x >= 10) print(x / 10);
  putchar(x % 10 + '0');
}
template <typename T>
inline void pr(T x) {
  print(x), putchar('\n');
}
template <typename T1, typename T2>
void chkmax(T1 &A, T2 B) {
  A = A >= B ? A : B;
}
template <typename T1, typename T2>
void chkmin(T1 &A, T2 B) {
  A = A <= B ? A : B;
}
int n, m, a[N], op[N], l[N], r[N], x[N], ans[N];
int fa[N], c[N];
int getf(int x) { return fa[x] == x ? x : fa[x] = getf(fa[x]); }
int id[N], d, siz[N];
int L[N], R[N], del[N];
int main() {
  sc(n), sc(m);
  int mi = 1e9;
  for (int i = 1; i <= n; i++) sc(a[i]), chkmin(mi, a[i]);
  for (int i = 1; i <= m; i++) sc(op[i]), sc(l[i]), sc(r[i]), sc(x[i]);
  const int blo = 707;
  int k = (n - 1) / blo + 1;
  for (int i = 1; i <= k; i++) L[i] = (i - 1) * blo + 1, R[i] = min(n, i * blo);
  for (int pos = 1; pos <= k; pos++) {
    int ma = 0;
    for (int i = L[pos]; i <= R[pos]; i++) {
      if (!id[a[i]])
        id[a[i]] = i, fa[i] = i, c[i] = a[i];
      else
        fa[i] = id[a[i]];
      ++siz[a[i]];
      chkmax(ma, a[i]);
    }
    bool fg = 1;
    for (int j = 1; j <= m; j++) {
      int op = ::op[j], l = ::l[j], r = ::r[j], x = ::x[j];
      chkmax(l, L[pos]), chkmin(r, R[pos]);
      if (l > r) continue;
      if (op == 1) {
        if (l == L[pos] && r == R[pos]) {
          if (x - d <= ma / 2) {
            for (int i = -d; i <= x - d; i++)
              if (id[i]) {
                int f = getf(id[i]), s = siz[i], y = i + x;
                id[i] = 0, c[f] = 0, siz[i] = 0;
                if (!id[y])
                  id[y] = f, c[f] = y;
                else
                  fa[f] = id[y];
                siz[y] += s;
              }
            d -= x;
          } else {
            for (int i = x - d + 1; i <= ma; i++)
              if (id[i]) {
                int f = getf(id[i]), s = siz[i], y = i - x;
                id[i] = 0, c[f] = 0, siz[i] = 0;
                if (!id[y])
                  id[y] = f, c[f] = y;
                else
                  fa[f] = id[y];
                siz[y] += s;
              }
            chkmin(ma, max(ma - x, x - d));
          }
        } else {
          for (int i = L[pos]; i <= R[pos]; i++) {
            int f = getf(i);
            a[i] = c[f] + d;
            if (l <= i && i <= r && a[i] > x) a[i] -= x;
          }
          for (int i = L[pos]; i <= R[pos]; i++) {
            int f = getf(i), g = c[f];
            id[g] = siz[g] = fa[i] = 0;
          }
          ma += d;
          d = 0;
          for (int i = L[pos]; i <= R[pos]; i++) {
            if (!id[a[i]])
              id[a[i]] = i, fa[i] = i, c[i] = a[i];
            else
              fa[i] = id[a[i]];
            ++siz[a[i]];
          }
        }
      } else {
        x -= d;
        if (l == L[pos] && r == R[pos]) {
          ans[j] += siz[x];
        } else {
          for (int i = l; i <= r; i++) {
            int f = getf(i);
            if (c[f] == x)
              ++ans[j];
            else
              fg = 0;
          }
        }
      }
    }
    for (int i = L[pos]; i <= R[pos]; i++) {
      int f = getf(i), g = c[f];
      id[g] = siz[g] = fa[i] = 0;
    }
    d = 0;
    if (fg && mi == 1e5) {
      while (m--) pr(n);
      return 0;
    }
  }
  for (int i = 1; i <= m; i++)
    if (op[i] == 2) pr(ans[i]);
  return 0;
}
