#include <bits/stdc++.h>
const int N = 100010, M = 198, K = 9;
int n, m, i, l, r, x, op, v[N], w[N], f[N], cnt[N], st[M], en[M], mx[M], tag[M],
    a[M][N];
inline void read(int& x) { scanf("%d", &x); }
int F(int x) { return f[x] == x ? x : f[x] = F(f[x]); }
inline void merge(int x, int y) {
  f[y] = x;
  cnt[x] += cnt[y];
}
inline void remake(int o, int l, int r, int x) {
  int i, j, L = st[o], R = en[o], t = tag[o], m = 0;
  for (i = L; i <= R; i++) a[o][w[i] = v[F(i)]] = 0;
  for (i = l; i <= r; i++)
    if (w[i] - t > x) w[i] -= x;
  for (i = L; i <= R; i++) {
    f[i] = i, cnt[i] = 1;
    j = v[i] = w[i];
    if (j > m) m = j;
    if (!a[o][j])
      a[o][j] = i;
    else
      merge(a[o][j], i);
  }
  mx[o] = m;
}
inline void add(int o, int x) {
  int m = mx[o], t = tag[o];
  if (m - t <= x) return;
  int i;
  if (m - t <= (x << 1)) {
    for (i = x + 1 + t; x <= m; i++)
      if (a[o][i]) {
        if (!a[o][i - x])
          v[a[o][i - x] = a[o][i]] = i - x;
        else
          merge(a[o][i - x], a[o][i]);
        a[o][i] = 0;
      }
    for (i = x + t; !a[o][i]; i--)
      ;
    mx[o] = i;
  } else {
    for (i = x + t; i > t; i--)
      if (a[o][i]) {
        if (!a[o][i + x])
          v[a[o][i + x] = a[o][i]] = i + x;
        else
          merge(a[o][i + x], a[o][i]);
        a[o][i] = 0;
      }
    tag[o] += x;
  }
}
inline void change(int l, int r, int x) {
  int L = l >> K, R = r >> K;
  if (L == R) {
    remake(L, l, r, x);
    return;
  }
  remake(L, l, en[L], x);
  remake(R, st[R], r, x);
  if (n < 100)
    for (L++; L < R; L++) add(L, x);
}
inline int ask(int l, int r, int x) {
  int L = l >> K, R = r >> K, i, ans = 0;
  if (n > 100) return 0;
  if (L == R) {
    for (i = l; i <= r; i++)
      if (v[F(i)] - tag[L] == x) ans++;
    return ans;
  }
  for (i = l; (i >> K) == L; i++)
    if (v[F(i)] - tag[L] == x) ans++;
  for (i = r; (i >> K) == R; i--)
    if (v[F(i)] - tag[R] == x) ans++;
  for (L++; L < R; L++)
    if (x + tag[L] < N) ans += v[F(a[L][x + tag[L]])];
  return ans;
}
int main() {
  read(n), read(m);
  for (i = 1; i <= n; i++) {
    f[i] = i, cnt[i] = 1;
    read(v[i]);
    if (v[i] > mx[i >> K]) mx[i >> K] = v[i];
    if (!a[i >> K][v[i]])
      a[i >> K][v[i]] = i;
    else
      merge(a[i >> K][v[i]], i);
  }
  for (i = 1; i <= n; i++) en[i >> K] = i;
  for (i = n; i; i--) st[i >> K] = i;
  while (m--) {
    read(op), read(l), read(r), read(x);
    if (op == 1)
      change(l, r, x);
    else
      printf("%d\n", ask(l, r, x));
  }
}
