#include <bits/stdc++.h>
using namespace std;
int S, n, m, i, op, l, r, x, an, cnt[555][111111], F[555][111111], a[111111],
    bl[111111], mx[111111], mi[111111], tag[111111];
int fd(int x, int z) {
  return (!F[x][z] || F[x][z] == z) ? F[x][z] = z : F[x][z] = fd(x, F[x][z]);
}
void rbd(int B) {
  for (int i = B * S - S + 1; i <= min(B * S, n); i++) {
    a[i] = fd(B, a[i]);
    cnt[B][a[i]]--;
    if (a[i] - tag[B] > x && l <= i && i <= r) a[i] -= x;
    cnt[B][a[i]]++;
  }
}
void cg(int B) {
  if (mi[B] + x > mx[B]) return;
  if (mi[B] + x + x <= mx[B]) {
    tag[B] += x;
    for (int i = mi[B] + 1; i <= mi[B] + x; i++) {
      F[B][i] = i + x;
      cnt[B][i + x] += cnt[B][i];
      cnt[B][i] = 0;
    }
    mi[B] += x;
  } else {
    for (int i = mi[B] + x + 1; i <= mx[B]; i++) {
      F[B][i] = i - x;
      cnt[B][i - x] += cnt[B][i];
      cnt[B][i] = 0;
    }
    mx[B] = mi[B] + x;
  }
}
int qu(int B) {
  int v = 0;
  for (int i = B * S - S + 1; i <= min(B * S, n); i++) {
    a[i] = fd(B, a[i]);
    if (a[i] == x + tag[B]) v++;
  }
  return v;
}
int qu2(int B) {
  if (x + tag[B] >= mi[B] && x + tag[B] <= mx[B]) return cnt[B][x + tag[B]];
  return 0;
}
int main() {
  scanf("%d%d", &n, &m);
  S = 300;
  for (i = 1; i <= n; i++)
    scanf("%d", &a[i]), bl[i] = (i - 1) / S + 1, cnt[bl[i]][a[i]]++;
  for (i = 1; i <= bl[n]; i++) mx[i] = 100001;
  for (; m--;) {
    scanf("%d%d%d%d", &op, &l, &r, &x);
    if (op == 1) {
      if (bl[l] == bl[r])
        rbd(bl[l]);
      else {
        rbd(bl[l]);
        rbd(bl[r]);
        for (i = bl[l] + 1; i < bl[r]; i++) cg(i);
      }
    } else {
      if (bl[l] == bl[r])
        printf("%d\n", qu(bl[l]));
      else {
        an = qu(bl[l]) + qu(bl[r]);
        for (i = bl[l] + 1; i < bl[r]; i++) an += qu2(i);
        printf("%d\n", an);
      }
    }
  }
}
