#include <bits/stdc++.h>
using namespace std;
template <class T>
void mx(T& a, const T& b) {
  if (a < b) a = b;
}
template <class T>
void mn(T& a, const T& b) {
  if (b < a) a = b;
}
const int MN = 1e5 + 100;
const int MV = 1e5 + 100;
const int MB = 210;
const int ML = 500;
template <int MS = MV>
struct DSU {
 public:
  int M;
  int p[MS], c[MS], r[MS], v[MS];
  void i(int* s, int* e) {
    M = 0;
    for (int* t = s; t != e; t++) mx(M, *t);
    for (int j = 0; j <= M; j++) p[j] = j, v[j] = j, c[j] = 0, r[j] = 0;
    for (int* t = s; t != e; t++) c[*t]++;
  }
  int f(int n) {
    if (n == p[n]) return n;
    return p[n] = f(p[n]);
  }
  bool m(int a, int b) {
    a = f(a), b = f(b);
    if (a == b) return false;
    bool z = false;
    if (r[a] < r[b]) swap(v[a], v[b]), swap(a, b);
    if (r[a] == r[b]) r[a]++;
    p[b] = a, c[v[a]] += c[v[b]], c[v[b]] = 0, r[b] = -1;
    return true;
  }
  int operator[](const int& x) {
    if (x > M)
      return 0;
    else
      return c[f(x)];
  }
};
struct DAT {
 public:
  DSU<> v;
  int d;
  int *s, *e;
  void res() {
    v.i(s, e);
    d = 0;
  }
  void init(int* l, int* r) {
    s = l, e = r;
    res();
  }
  void upd(int x) {
    if (x >= v.M - d) return;
    if (x << 1 > v.M - d) {
      for (int i = d + x + 1; i <= v.M; i++) v.m(i, i - x);
      mn(v.M, d + x);
    } else {
      for (int i = 0; i <= x; i++) v.m(i + d, i + d + x);
      d += x;
    }
  }
  void upd(int l, int r, int x) {
    if (not(l < r)) return;
    for (int *t = s, i = 0; t != e; t++, i++) {
      *t = v.v[v.f(*t)] - d;
      if (l <= i and i<r and * t> x) (*t) -= x;
    }
    res();
  }
  int operator[](const int& x) {
    if (x + d > v.M)
      return 0;
    else
      return v.c[x + d];
  }
  int qry(int l, int r, int x) {
    int f = 0;
    for (int i = l; i < r; i++) f += v.v[v.f(*(s + i))] - d == x;
    return f;
  }
};
DAT v[MB];
int N, a[MN], M;
int main() {
  scanf("%d%d", &N, &M);
  for (int i = 0; i < N; i++) scanf("%d", a + i);
  for (int i = 0, j = 0; i < N; i += ML, j++) {
    if (i + ML > N) {
      v[j].init(a + i, a + N);
      break;
    } else {
      v[j].init(a + i, a + i + ML);
    }
  }
  for (int i = 0, o, l, r, x; i < M; i++) {
    scanf("%d%d%d%d", &o, &l, &r, &x), --l, --r;
    if (o == 1) {
      if (l / ML == r / ML)
        v[l / ML].upd(l % ML, 1 + (r % ML), x);
      else {
        v[l / ML].upd(l % ML, ML, x);
        v[r / ML].upd(0, 1 + (r % ML), x);
        for (int j = l / ML + 1; j < r / ML; j++) v[j].upd(x);
      }
    } else {
      if (l / ML == r / ML)
        printf("%d\n", v[l / ML].qry(l % ML, 1 + (r % ML), x));
      else {
        int f = 0;
        f += v[l / ML].qry(l % ML, ML, x);
        f += v[r / ML].qry(0, 1 + (r % ML), x);
        for (int j = l / ML + 1; j < r / ML; j++) f += v[j][x];
        printf("%d\n", f);
      }
    }
  }
  return 0;
}
