#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
long long powmod(long long a, long long b) {
  long long res = 1;
  a %= mod;
  assert(b >= 0);
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
const int N = 101000;
short cnt[410][N];
int ff[410][N];
int fl[510], fr[510], pl[510], pr[510], off[510], a[N], x, l, r;
int n, m, T, B, ty;
pair<int, int> rg[510];
int find(int x, int c) {
  if (ff[x][c] == 0 || ff[x][c] == c)
    return ff[x][c] = c;
  else
    return ff[x][c] = find(x, ff[x][c]);
}
void rebuild(int c, int l, int r) {
  for (int j = fl[c]; j < fr[c] + 1; j++) a[j] = find(c, a[j]);
  for (int j = l; j < r + 1; j++)
    if (a[j] - off[c] > x) {
      cnt[c][a[j]]--;
      a[j] -= x;
      cnt[c][a[j]]++;
    }
}
int query(int c1, int l, int r) {
  for (int j = fl[c1]; j < fr[c1] + 1; j++) a[j] = find(c1, a[j]);
  int cnt = 0;
  for (int j = l; j < r + 1; j++)
    if (find(c1, a[j]) == x + off[c1]) cnt++;
  return cnt;
}
int query(int c) {
  if (x + off[c] >= rg[c].first && x + off[c] <= rg[c].second)
    return cnt[c][x + off[c]];
  else
    return 0;
}
void gao(int i) {
  if (rg[i].first + x > rg[i].second) return;
  if (rg[i].first + x + x <= rg[i].second) {
    off[i] += x;
    for (int j = rg[i].first + 1; j < rg[i].first + x + 1; j++) {
      ff[i][j] = j + x;
      cnt[i][j + x] += cnt[i][j];
      cnt[i][j] = 0;
    }
    rg[i].first += x;
  } else {
    for (int j = rg[i].second + 1 - 1; j >= rg[i].first + x + 1; j--) {
      ff[i][j] = j - x;
      cnt[i][j - x] += cnt[i][j];
      cnt[i][j] = 0;
    }
    rg[i].second = rg[i].first + x;
  }
}
int main() {
  scanf("%d%d", &n, &m);
  B = 2 * sqrt(n);
  for (int i = 0; i < n; i++) scanf("%d", a + i);
  for (int i = 0; i < n; i++) cnt[i / B][a[i]]++;
  T = (n - 1) / B + 1;
  for (int i = 0; i < T; i++) rg[i] = make_pair(0, 100001), off[i] = 0;
  for (int i = 0; i < T; i++) fl[i] = i * B, fr[i] = min(i * B + B - 1, n - 1);
  for (int i = 0; i < m; i++) {
    scanf("%d%d%d%d", &ty, &l, &r, &x);
    --l;
    --r;
    if (l / B == r / B) {
      if (ty == 1)
        rebuild(l / B, l, r);
      else
        printf("%d\n", query(l / B, l, r));
    } else {
      int c1 = l / B, c2 = r / B;
      int ret = 0;
      if (ty == 1) {
        rebuild(c1, l, fr[c1]);
        rebuild(c2, fl[c2], r);
        for (int j = c1 + 1; j < c2; j++) gao(j);
      } else {
        ret += query(c1, l, fr[c1]);
        ret += query(c2, fl[c2], r);
        for (int j = c1 + 1; j < c2; j++) ret += query(j);
        printf("%d\n", ret);
      }
    }
  }
}
