#include <bits/stdc++.h>
using namespace std;
int n, m, bsize;
int fa[100005], a[100005], fir[325][100005], cnt[100005], v[100005], tag[325],
    mx[325], belong[100005];
int l[325], r[325];
int Read() {
  int tmp = 0, flag = 1;
  char c;
  for (c = getchar(); !isdigit(c); c = getchar())
    if (c == '-') flag = -flag;
  for (; isdigit(c); c = getchar()) tmp = (tmp << 3) + (tmp << 1) + c - '0';
  return tmp * flag;
}
int f(int rt) { return fa[rt] == rt ? rt : fa[rt] = f(fa[rt]); }
void update(int rt) {
  while (!~fir[rt][mx[rt]]) --mx[rt];
  return;
}
void build(int rt) {
  for (int i = l[rt]; i <= r[rt]; i++) {
    a[i] = v[f(i)];
    fir[rt][a[i]] = -1;
  }
  for (int i = l[rt]; i <= r[rt]; i++) {
    cnt[i] = 1;
    fa[i] = i;
  }
  for (int i = l[rt]; i <= r[rt]; i++) {
    if (~fir[rt][a[i]]) {
      cnt[fir[rt][a[i]]] += cnt[i];
      fa[i] = fir[rt][a[i]];
    } else {
      fir[rt][a[i]] = i;
      v[i] = a[i];
    }
  }
  return;
}
void chg(int rt, int ll, int rr, int x) {
  for (int i = l[rt]; i <= r[rt]; i++) {
    a[i] = v[f(i)];
  }
  for (int i = l[rt]; i <= r[rt]; i++) {
    fir[rt][a[i]] = -1;
  }
  for (int i = ll; i <= rr; i++) {
    if (a[i] - tag[rt] > x) a[i] -= x;
  }
  for (int i = l[rt]; i <= r[rt]; i++) {
    v[i] = a[i];
    fa[i] = i;
  }
  build(rt);
  return;
}
void modify(int ll, int rr, int x) {
  if (belong[ll] == belong[rr]) {
    chg(belong[ll], ll, rr, x);
    return;
  }
  chg(belong[ll], ll, r[belong[ll]], x);
  chg(belong[rr], l[belong[rr]], rr, x);
  for (int i = belong[ll] + 1; i < belong[rr]; i++) {
    if (2 * x <= mx[i] - tag[i]) {
      for (int j = tag[i] + 1; j <= x + tag[i]; j++) {
        if (~fir[i][j]) {
          if (~fir[i][j + x]) {
            cnt[fir[i][j + x]] += cnt[fir[i][j]];
            fa[fir[i][j]] = fir[i][j + x];
            fir[i][j] = -1;
          } else {
            fa[fir[i][j]] = fir[i][j + x];
            v[fir[i][j]] = x + j;
            fir[i][j] = -1;
          }
        }
      }
      tag[i] += x;
    } else {
      for (int j = x + tag[i] + 1; j <= mx[i]; j++) {
        if (~fir[i][j]) {
          if (~fir[i][j - x]) {
            cnt[fir[i][j - x]] += cnt[fir[i][j]];
            fa[fir[i][j]] = fir[i][j - x];
            fir[i][j] = -1;
          } else {
            fir[i][j - x] = fir[i][j];
            v[fir[i][j]] = j - x;
            fir[i][j] = -1;
          }
        }
      }
      update(i);
    }
  }
  return;
}
int query(int ll, int rr, int x) {
  int ans = 0;
  if (belong[ll] == belong[rr]) {
    for (int i = ll; i <= rr; i++) {
      if (v[f(i)] - tag[belong[ll]] == x) {
        ans++;
      }
    }
    return ans;
  }
  for (int i = ll; i <= r[belong[ll]]; i++) {
    if (v[f(i)] - tag[belong[ll]] == x) {
      ans++;
    }
  }
  for (int i = l[belong[rr]]; i <= rr; i++) {
    if (v[f(i)] - tag[belong[rr]] == x) {
      ans++;
    }
  }
  for (int i = belong[ll] + 1; i < belong[rr]; i++) {
    if (x + tag[i] <= 100000 && ~fir[i][x + tag[i]]) {
      ans += cnt[fir[i][x + tag[i]]];
    }
  }
  return ans;
}
int main() {
  memset(fir, -1, sizeof(fir));
  n = Read();
  m = Read();
  bsize = sqrt(n);
  for (int i = 1; i <= n; i++) {
    v[i] = a[i] = Read();
    fa[i] = i;
    belong[i] = (i - 1) / bsize + 1;
    mx[belong[i]] = max(mx[belong[i]], a[i]);
  }
  for (int i = 1; i <= belong[n]; i++) {
    l[i] = (i - 1) * bsize + 1;
    r[i] = min(i * bsize, n);
    build(i);
  }
  for (int i = 1; i <= m; i++) {
    int op, ll, rr, x;
    op = Read();
    ll = Read();
    rr = Read();
    x = Read();
    if (op == 1) {
      modify(ll, rr, x);
    } else {
      printf("%d\n", query(ll, rr, x));
    }
  }
  return 0;
}
