#include <bits/stdc++.h>
const int bs = 316;
int n, m;
int now;
int a[524288];
int fa[524288], size[524288];
int findroot(int x) {
  if (fa[x] == x) {
    return x;
  }
  return fa[x] = findroot(fa[x]);
}
int mx, tag, fir[524288];
void build() {
  if (now == 0 || now == n / bs) {
    return;
  }
  mx = 0;
  tag = 0;
  for (int i = now * bs; i < now * bs + bs; i++) {
    if (a[i] > mx) {
      mx = a[i];
    }
    if (!fir[a[i]]) {
      fir[a[i]] = i;
      fa[i] = i;
      size[i] = 1;
    } else {
      fa[i] = fir[a[i]];
      size[fir[a[i]]]++;
    }
  }
}
void pushdown() {
  if (now == 0 || now == n / bs) {
    return;
  }
  for (int i = now * bs; i < now * bs + bs; i++) {
    if (fa[i] == i) {
      fir[a[i]] = 0;
    } else {
      a[i] = a[findroot(i)];
    }
  }
  for (int i = now * bs; i < now * bs + bs; i++) {
    a[i] -= tag;
  }
}
void change(int k) {
  if (mx - k < k) {
    for (int i = mx; i > k; i--) {
      if (!fir[i + tag]) {
        continue;
      }
      a[fir[i + tag]] -= k;
      if (!fir[i + tag - k]) {
        fir[i + tag - k] = fir[i + tag];
      } else if (fir[i + tag - k] < fir[i + tag]) {
        fa[fir[i + tag]] = fir[i + tag - k];
        size[fir[i + tag - k]] += size[fir[i + tag]];
      } else {
        fa[fir[i + tag - k]] = fir[i + tag];
        size[fir[i + tag]] += size[fir[i + tag - k]];
        fir[i + tag - k] = fir[i + tag];
      }
      fir[i + tag] = 0;
    }
    while (fir[mx + tag] == 0) {
      mx--;
    }
  } else {
    for (int i = 1; i <= k; i++) {
      if (!fir[i + tag]) {
        continue;
      }
      a[fir[i + tag]] += k;
      if (!fir[i + tag + k]) {
        fir[i + tag + k] = fir[i + tag];
      } else if (fir[i + tag + k] < fir[i + tag]) {
        fa[fir[i + tag]] = fir[i + tag + k];
        size[fir[i + tag + k]] += size[fir[i + tag]];
      } else {
        fa[fir[i + tag + k]] = fir[i + tag];
        size[fir[i + tag]] += size[fir[i + tag + k]];
        fir[i + tag + k] = fir[i + tag];
      }
      fir[i + tag] = 0;
    }
    tag += k;
    mx -= k;
  }
}
int query(int x) {
  if (x > mx) {
    return 0;
  }
  if (!fir[x + tag]) {
    return 0;
  }
  return size[fir[x + tag]];
}
int opt[524288], l[524288], r[524288], x[524288], ans[524288];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  for (int i = 0; i < m; i++) {
    scanf("%d%d%d%d", &opt[i], &l[i], &r[i], &x[i]);
  }
  for (now = 0; now <= n / bs; now++) {
    build();
    for (int i = 0; i < m; i++) {
      if (now == l[i] / bs || now == r[i] / bs) {
        pushdown();
        for (int j = now * bs; j < now * bs + bs; j++) {
          if (j < l[i] || j > r[i]) {
            continue;
          }
          if (opt[i] == 1) {
            if (a[j] > x[i]) {
              a[j] -= x[i];
            }
          } else {
            if (a[j] == x[i]) {
              ans[i]++;
            }
          }
        }
        build();
      }
      if (now > l[i] / bs && now < r[i] / bs) {
        if (opt[i] == 1) {
          change(x[i]);
        } else {
          ans[i] += query(x[i]);
        }
      }
    }
    pushdown();
  }
  for (int i = 0; i < m; i++) {
    if (opt[i] == 2) {
      printf("%d\n", ans[i]);
    }
  }
  return 0;
}
