#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long INFF = 0x3f3f3f3f3f3f3f3fll;
const long long M = 1e9 + 7;
const long long maxn = 1e6 + 7;
const double eps = 0.00000001;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
template <typename T>
inline T abs(T a) {
  return a > 0 ? a : -a;
}
template <typename T>
inline T powMM(T a, T b) {
  T ret = 1;
  for (; b; b >>= 1ll, a = 1ll * a * a % M)
    if (b & 1) ret = 1ll * ret * a % M;
  return ret;
}
const int SIZE = 300, MAX = 100000;
int tot;
int block[maxn];
int cnt[407][100007], fa[407][100007];
int tag[407], big[407];
int a[100007];
inline int getfa(int i, int &x) {
  if (fa[i][x] == x) return x;
  return x = fa[i][x] = getfa(i, fa[i][x]);
}
int main() {
  int i, j, k;
  int n, m;
  for (i = 1; i <= MAX; i++) block[i] = i / SIZE;
  for (i = 0; i <= MAX / SIZE; i++)
    for (j = 1; j <= MAX; j++) fa[i][j] = j;
  scanf("%d%d", &n, &m);
  for (i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    cnt[block[i]][a[i]]++;
    big[block[i]] = max(big[block[i]], a[i]);
  }
  for (k = 1; k <= m; k++) {
    int t, l, r, x, ans = 0;
    scanf("%d%d%d%d", &t, &l, &r, &x);
    if (block[l] == block[r]) {
      if (t == 1) {
        for (i = l; i <= r; i++)
          if (getfa(block[i], a[i]) > x + tag[block[i]]) {
            cnt[block[i]][a[i]]--;
            a[i] -= x;
            cnt[block[i]][a[i]]++;
          }
      } else
        for (i = l; i <= r; i++)
          if (getfa(block[i], a[i]) == x + tag[block[i]]) ans++;
    } else {
      if (t == 1) {
        int pos = (block[l] + 1) * SIZE - 1;
        for (i = l; i <= pos; i++)
          if (getfa(block[i], a[i]) > x + tag[block[i]]) {
            cnt[block[i]][a[i]]--;
            a[i] -= x;
            cnt[block[i]][a[i]]++;
          }
        for (i = block[l] + 1; i <= block[r] - 1; i++) {
          if (tag[i] + x * 2 <= big[i]) {
            for (j = tag[i] + 1; j <= tag[i] + x; j++) {
              cnt[i][j + x] += cnt[i][j];
              cnt[i][j] = 0;
              fa[i][j] = j + x;
            }
            tag[i] += x;
          } else if (x < big[i]) {
            for (j = x + 1; j <= big[i]; j++) {
              cnt[i][j - x] += cnt[i][j];
              cnt[i][j] = 0;
              fa[i][j] = j - x;
            }
            big[i] = x;
          }
        }
        pos = block[r] * SIZE;
        for (i = pos; i <= r; i++)
          if (getfa(block[i], a[i]) > x + tag[block[i]]) {
            cnt[block[i]][a[i]]--;
            a[i] -= x;
            cnt[block[i]][a[i]]++;
          }
      } else {
        int pos = (block[l] + 1) * SIZE - 1;
        for (i = l; i <= pos; i++)
          if (getfa(block[i], a[i]) == x + tag[block[i]]) ans++;
        for (i = block[l] + 1; i <= block[r] - 1; i++)
          ans += cnt[i][x + tag[i]];
        pos = block[r] * SIZE;
        for (i = pos; i <= r; i++)
          if (getfa(block[i], a[i]) == x + tag[block[i]]) ans++;
      }
    }
    if (t == 2) printf("%d\n", ans);
  }
}
