#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
const int sq = 320;
int n, m, a[maxn], b[maxn], cnt[sq + 10][maxn], x, mn[sq + 10], mx[sq + 10],
    ds[sq + 10][maxn], ad[sq + 10], t, l, r;
int find(int bl, int u) {
  return ds[bl][u] == u ? u : ds[bl][u] = find(bl, ds[bl][u]);
}
void fix(int u) {
  for (int i = u * sq; i < min(n, u * sq + sq); ++i) {
    a[i] = find(u, a[i]);
    if (a[i] - ad[u] <= x || i < l || i > r) continue;
    cnt[u][a[i]]--;
    a[i] -= x;
    cnt[u][a[i]]++;
  }
}
void chn(int u) {
  if (mn[u] + x > mx[u]) return;
  if (mn[u] + 2 * x <= mx[u]) {
    ad[u] += x;
    for (int i = mn[u] + 1; i < mn[u] + x + 1; ++i) {
      ds[u][i] = i + x;
      cnt[u][i + x] += cnt[u][i];
      cnt[u][i] = 0;
    }
    mn[u] += x;
  } else {
    for (int i = mn[u] + x + 1; i < mx[u] + 1; ++i) {
      ds[u][i] = i - x;
      cnt[u][i - x] += cnt[u][i];
      cnt[u][i] = 0;
    }
    mx[u] = mn[u] + x;
  }
}
int q1(int u) {
  int o = 0;
  for (int i = sq * u; i < min(n, sq * u + sq); ++i) {
    a[i] = find(u, a[i]);
    if (a[i] - ad[u] == x && l <= i && i <= r) {
      o++;
    }
  }
  return o;
}
int q2(int u) {
  if (x + ad[u] >= mn[u] && mx[u] >= x + ad[u]) {
    return cnt[u][x + ad[u]];
  }
  return 0;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    b[i] = i / sq;
    cnt[b[i]][a[i]]++;
  }
  for (int i = b[0]; i < b[n - 1] + 1; ++i) {
    mx[i] = 100000;
    for (int j = 1; j < 100001; ++j) {
      ds[i][j] = j;
    }
  }
  while (m--) {
    cin >> t >> l >> r >> x;
    l--;
    r--;
    if (t == 1) {
      if (b[l] == b[r]) {
        fix(b[l]);
        continue;
      }
      fix(b[l]);
      fix(b[r]);
      for (int i = b[l] + 1; i < b[r]; ++i) {
        chn(i);
      }
    } else {
      int re = 0;
      if (b[l] == b[r]) {
        re += q1(b[l]);
        cout << re << '\n';
        continue;
      }
      re += q1(b[l]) + q1(b[r]);
      for (int i = b[l] + 1; i < b[r]; ++i) {
        re += q2(i);
      }
      cout << re << '\n';
    }
  }
  return 0;
}
