#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 100;
const int B = 333;
int fa[N], a[B][N], head[B][N], L[N], R[N], pos[N], num[N];
int Find(int x) { return x == fa[x] ? x : fa[x] = Find(fa[x]); }
void pushdown(int x) {
  for (int i = x * B; i < x * B + B; i++) {
    num[i] = pos[Find(i)];
    a[x][num[i]] = 0;
    head[x][num[i]] = -1;
  }
}
void update(int x) {
  R[x] = 0;
  for (int i = x * B; i < x * B + B; i++) {
    R[x] = max(R[x], num[i]);
    if (head[x][num[i]] == -1) {
      head[x][num[i]] = i;
      pos[i] = num[i];
      fa[i] = i;
    } else
      fa[i] = head[x][num[i]];
    a[x][num[i]]++;
  }
}
void mergee(int x, int p, int q) {
  if (head[x][p] != -1) {
    if (head[x][q] == -1) {
      head[x][q] = head[x][p];
      a[x][q] = a[x][p];
      pos[head[x][p]] = q;
    } else {
      fa[head[x][p]] = head[x][q];
      a[x][q] += a[x][p];
    }
  }
}
void solve(int l, int r, int x) {
  int ll = l / B, rr = r / B;
  if (ll == rr) {
    pushdown(ll);
    for (int i = l; i <= r; i++) {
      if (num[i] > L[ll] + x) num[i] -= x;
    }
    update(ll);
  } else {
    pushdown(ll), pushdown(rr);
    for (int i = l; i < ll * B + B; i++) {
      if (num[i] > L[ll] + x) num[i] -= x;
    }
    for (int i = rr * B; i <= r; i++) {
      if (num[i] > L[rr] + x) num[i] -= x;
    }
    update(ll), update(rr);
    for (int i = ll + 1; i < rr; i++) {
      if (R[i] > 2 * x + L[i]) {
        for (int j = L[i] + 1; j <= L[i] + x; j++) mergee(i, j, j + x);
        L[i] += x;
      } else if (R[i] > x + L[i]) {
        for (int j = R[i]; j > L[i] + x; j--) {
          mergee(i, j, j - x);
        }
        R[i] = x + L[i];
      }
    }
  }
}
int query(int l, int r, int x) {
  int ll = l / B, rr = r / B;
  if (ll == rr) {
    pushdown(ll);
    int ans = 0;
    for (int i = l; i <= r; i++)
      if (L[ll] + x == num[i]) ans++;
    update(ll);
    return ans;
  } else {
    pushdown(ll), pushdown(rr);
    int ans = 0;
    for (int i = l; i < ll * B + B; i++) {
      if (L[ll] + x == num[i]) ans++;
    }
    for (int i = rr * B; i <= r; i++) {
      if (L[rr] + x == num[i]) ans++;
    }
    update(ll), update(rr);
    for (int i = ll + 1; i < rr; i++)
      if (L[i] + x <= R[i]) ans += a[i][L[i] + x];
    return ans;
  }
}
int main() {
  int n, m;
  memset(head, -1, sizeof(head));
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%d", &num[i]);
  for (int i = 0; i <= n / B; i++) update(i);
  for (int i = 1; i <= m; i++) {
    int op, l, r, x;
    scanf("%d %d %d %d", &op, &l, &r, &x);
    if (op == 1)
      solve(l, r, x);
    else
      printf("%d\n", query(l, r, x));
  }
  return 0;
}
