#include <bits/stdc++.h>
const int N = 100005;
const int bit = 9;
int n, m, a[N], tag[(N >> bit) + 1], max[(N >> bit) + 1];
std::list<int> list[(N >> bit) + 1][N];
void clear(int id) {
  for (int i = id << bit; i < id + 1 << bit && i < n; ++i)
    list[id][a[i]].clear();
  for (int i = id << bit; i < id + 1 << bit && i < n; ++i) a[i] += tag[id];
  tag[id] = 0;
}
void rebuild(int id) {
  max[id] = 0;
  for (int i = id << bit; i < id + 1 << bit && i < n; ++i)
    list[id][a[i]].push_back(i), max[id] = std::max(max[id], a[i]);
}
void modify(int id, int x) {
  if (max[id] > 2 * x) {
    max[id] -= x;
    for (int i = 1; i <= x; ++i)
      list[id][i + x - tag[id]].splice(list[id][i + x - tag[id]].begin(),
                                       list[id][i - tag[id]]);
    tag[id] -= x;
  } else if (max[id] > x) {
    max[id] -= x;
    for (int i = x + 1; i <= 2 * x; ++i)
      list[id][i - x - tag[id]].splice(list[id][i - x - tag[id]].begin(),
                                       list[id][i - tag[id]]);
  }
}
void modify(int l, int r, int x) {
  int bl = l >> bit, br = r >> bit;
  if (bl == br) {
    clear(bl);
    for (int i = l; i <= r; ++i)
      if (a[i] > x) a[i] -= x;
    return rebuild(bl);
  }
  clear(bl), clear(br);
  for (int i = l; i < bl + 1 << bit; ++i)
    if (a[i] > x) a[i] -= x;
  for (int i = br << bit; i <= r; ++i)
    if (a[i] > x) a[i] -= x;
  rebuild(bl), rebuild(br);
  for (int i = bl + 1; i < br; ++i) modify(i, x);
}
int query(int l, int r, int x) {
  int bl = l >> bit, br = r >> bit, ans = 0;
  if (bl == br) {
    for (int i = l; i <= r; ++i)
      if (a[i] + tag[bl] == x) ++ans;
    return ans;
  }
  for (int i = l; i < bl + 1 << bit; ++i)
    if (a[i] + tag[bl] == x) ++ans;
  for (int i = br << bit; i <= r; ++i)
    if (a[i] + tag[br] == x) ++ans;
  for (int i = bl + 1; i < br; ++i)
    if (x >= tag[i]) ans += list[i][x - tag[i]].size();
  return ans;
}
int main() {
  std::ios::sync_with_stdio(0), std::cin.tie(0);
  std::cin >> n >> m;
  for (int i = 0; i < n; ++i) std::cin >> a[i];
  for (int i = 0; i << bit < n; ++i) rebuild(i);
  for (int i = 0; i < m; ++i) {
    int opt, l, r, x;
    std::cin >> opt >> l >> r >> x, --l, --r;
    if (opt == 1)
      modify(l, r, x);
    else
      std::cout << query(l, r, x) << '\n';
  }
  return 0;
}
