#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int n, m, i, j, k, w, l, r, x, ans, L, R, mid, bl[N], a[N], add[330],
    p[330 * N], sz[330 * N], lt[N], rt[N], s[330][330], t[330], g, len[330],
    num, tag[N * 330], pt[330][N];
int find(int x) { return !p[x] ? x : p[x] = find(p[x]); }
bool cmp(int a, int b) { return tag[find(a)] < tag[find(b)]; }
void work(int bl, int l, int r, int x) {
  int i, j;
  for (i = 1; i <= len[bl]; ++i) pt[bl][tag[find(s[bl][i])]] = 0;
  len[bl] = 0;
  for (i = lt[bl]; i <= rt[bl]; ++i) {
    j = tag[find(i)] + add[bl];
    if (i >= l && i <= r && j > x) j -= x;
    if (!pt[bl][j]) {
      ++num;
      p[i] = num;
      sz[num] = 1;
      s[bl][++len[bl]] = p[i];
      tag[num] = j;
      pt[bl][j] = num;
    } else {
      p[i] = pt[bl][j];
      sz[p[i]]++;
    }
  }
  sort(s[bl] + 1, s[bl] + 1 + len[bl], cmp);
  add[bl] = 0;
}
int main() {
  scanf("%d%d", &n, &m);
  for (i = 1; i <= n; ++i) scanf("%d", a + i);
  w = (int)sqrt(n);
  for (i = 1; i <= n; ++i) bl[i] = (i - 1) / w + 1;
  for (i = 1; i <= n; ++i) {
    if (!lt[bl[i]]) lt[bl[i]] = i;
    rt[bl[i]] = i;
  }
  num = n;
  for (i = 1; i <= n; ++i) {
    if (!pt[bl[i]][a[i]]) {
      ++num;
      p[i] = num;
      sz[num] = 1;
      s[bl[i]][++len[bl[i]]] = p[i];
      tag[num] = a[i];
      pt[bl[i]][a[i]] = num;
    } else {
      p[i] = pt[bl[i]][a[i]];
      sz[p[i]]++;
    }
  }
  for (i = 1; i <= bl[n]; ++i) sort(s[i] + 1, s[i] + 1 + len[i], cmp);
  while (m--) {
    scanf("%d", &i);
    if (i == 1) {
      scanf("%d%d%d", &l, &r, &x);
      if (bl[l] != bl[r]) {
        for (i = bl[l] + 1; i < bl[r]; ++i) {
          if (x - add[i] >= tag[find(s[i][len[i]])])
            j = len[i] + 1;
          else {
            L = 1, R = len[i];
            while (L < R) {
              mid = L + R >> 1;
              if (tag[find(s[i][mid])] > x - add[i])
                R = mid;
              else
                L = mid + 1;
            }
            j = L;
          }
          if (tag[find(s[i][len[i]])] - tag[find(s[i][1])] < 10 * x) {
            g = 0;
            for (k = 1; k < j; ++k) t[++g] = s[i][k];
            for (; j <= len[i]; ++j) {
              if (pt[i][tag[find(s[i][j])] - x]) {
                pt[i][tag[find(s[i][j])]] = 0;
                sz[pt[i][tag[find(s[i][j])] - x]] += sz[find(s[i][j])];
                p[find(s[i][j])] = pt[i][tag[find(s[i][j])] - x];
              } else {
                pt[i][tag[find(s[i][j])] - x] = pt[i][tag[find(s[i][j])]];
                pt[i][tag[find(s[i][j])]] = 0;
                tag[find(s[i][j])] -= x;
                t[++g] = find(s[i][j]);
              }
            }
            sort(t + 1, t + 1 + g, cmp);
            for (j = 1; j <= g; ++j) s[i][j] = t[j];
            len[i] = g;
          } else {
            g = 0;
            for (k = j; k <= len[i]; ++k) t[++g] = s[i][k];
            for (--j; j >= 1; --j) {
              if (pt[i][tag[find(s[i][j])] + x]) {
                pt[i][tag[find(s[i][j])]] = 0;
                sz[pt[i][tag[find(s[i][j])] + x]] += sz[find(s[i][j])];
                p[find(s[i][j])] = pt[i][tag[find(s[i][j])] + x];
              } else {
                pt[i][tag[find(s[i][j])] + x] = pt[i][tag[find(s[i][j])]];
                pt[i][tag[find(s[i][j])]] = 0;
                tag[find(s[i][j])] += x;
                t[++g] = find(s[i][j]);
              }
            }
            add[i] -= x;
            sort(t + 1, t + 1 + g, cmp);
            for (j = 1; j <= g; ++j) s[i][j] = t[j];
            len[i] = g;
          }
        }
        work(bl[l], l, rt[bl[l]], x);
        work(bl[r], lt[bl[r]], r, x);
      } else
        work(bl[l], l, r, x);
    } else {
      scanf("%d%d%d", &l, &r, &x);
      ans = 0;
      if (bl[l] != bl[r]) {
        for (i = bl[l] + 1; i < bl[r]; ++i) ans += sz[pt[i][x - add[i]]];
        for (i = l; i <= rt[bl[l]]; ++i)
          if (tag[find(i)] + add[bl[l]] == x) ++ans;
        for (i = lt[bl[r]]; i <= r; ++i)
          if (tag[find(i)] + add[bl[r]] == x) ++ans;
      } else {
        for (i = l; i <= r; ++i)
          if (tag[find(i)] + add[bl[i]] == x) ++ans;
      }
      printf("%d\n", ans);
    }
  }
  return 0;
}
