#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5, G = 320;
int n, m, f[N], cnt[N], Id[N], val[N], b[N], tag[G], a[314][N], mx[G], ans;
char c;
inline int read() {
  int x = 0, sig = 1;
  for (c = getchar(); c < '0' || c > '9'; c = getchar())
    if (c == '-') sig = -1;
  for (; c >= '0' && c <= '9'; c = getchar()) x = x * 10 + c - 48;
  return x * sig;
}
inline int Get(int x) { return (f[x] == x) ? x : f[x] = Get(f[x]); }
inline void Merge(int x, int y) {
  f[y] = x;
  cnt[x] += cnt[y];
}
inline void Change1(int l, int r, int x) {
  int i, j;
  for (j = l; Id[j - 1] == Id[j]; j--)
    ;
  for (i = j; Id[i] == Id[r]; i++) {
    b[i] = val[Get(i)];
    a[Id[i]][b[i]] = 0;
  }
  mx[Id[r]] = 0;
  for (i = l; i <= r; i++)
    if (b[i] - tag[Id[i]] > x) b[i] -= x;
  for (i = j; Id[i] == Id[r]; i++) {
    f[i] = i;
    cnt[i] = 1;
    val[i] = b[i];
    mx[Id[i]] = ((mx[Id[i]]) > (val[i]) ? (mx[Id[i]]) : (val[i]));
    if (!a[Id[i]][val[i]])
      a[Id[i]][val[i]] = i;
    else
      Merge(a[Id[i]][val[i]], i);
  }
}
inline void Change2(int l, int r, int x) {
  for (int i, j = l; j <= r; j++)
    if (tag[j] + x < mx[j]) {
      if (tag[j] + (x << 1) <= mx[j]) {
        for (i = tag[j] + x; i > tag[j]; i--)
          if (a[j][i]) {
            if (!a[j][i + x])
              val[a[j][i + x] = a[j][i]] = i + x;
            else
              Merge(a[j][i + x], a[j][i]);
            a[j][i] = 0;
          }
        tag[j] += x;
      } else {
        for (i = tag[j] + x + 1; i <= mx[j]; i++)
          if (a[j][i]) {
            if (!a[j][i - x])
              val[a[j][i - x] = a[j][i]] = i - x;
            else
              Merge(a[j][i - x], a[j][i]);
            a[j][i] = 0;
          }
        for (i = tag[j] + x; !a[j][i]; i--)
          ;
        mx[j] = i;
      }
    }
}
int main() {
  n = read();
  m = read();
  for (register int i = 1; i <= n; i++) {
    Id[i] = i / G;
    f[i] = i;
    cnt[i] = 1;
    val[i] = read();
    mx[Id[i]] = ((mx[Id[i]]) > (val[i]) ? (mx[Id[i]]) : (val[i]));
    if (!a[Id[i]][val[i]])
      a[Id[i]][val[i]] = i;
    else
      Merge(a[Id[i]][val[i]], i);
  }
  Id[0] = Id[n + 1] = -1;
  for (int typ, l, r, x, i; m--;) {
    typ = read();
    l = read();
    r = read();
    x = read();
    if (typ == 1) {
      if (Id[l] == Id[r]) {
        Change1(l, r, x);
        continue;
      }
      for (i = l; Id[i + 1] == Id[l]; i++)
        ;
      Change1(l, i, x);
      for (i = r; Id[i - 1] == Id[r]; i--)
        ;
      Change1(i, r, x);
      Change2(Id[l] + 1, Id[r] - 1, x);
    } else {
      ans = 0;
      if (Id[l] == Id[r]) {
        for (register int i = l; i <= r; i++)
          ans += (val[Get(i)] - tag[Id[i]] == x);
      } else {
        for (register int i = l; Id[i] == Id[l]; i++)
          ans += (val[Get(i)] - tag[Id[i]] == x);
        for (register int i = r; Id[i] == Id[r]; i--)
          ans += (val[Get(i)] - tag[Id[i]] == x);
        for (register int i = Id[l] + 1; i < Id[r]; i++)
          if (x + tag[i] < N) ans += cnt[a[i][x + tag[i]]];
      }
      printf("%d\n", ans);
    }
  }
  return 0;
}
