#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector")
#pragma GCC target("avx,tune=native")
#pragma GCC diagnostic ignored "-Wunused-result"
#pragma GCC diagnostic ignored "-Wunused-function"
using namespace std;
namespace {
namespace shik {
inline int read_char() {
  static char buf[1 << 16], *ptr = buf, *end_ptr = buf;
  if (ptr == end_ptr) {
    int len = fread(buf, 1, sizeof(buf), stdin);
    if (len <= 0) return EOF;
    ptr = buf;
    end_ptr = buf + len;
  }
  return *ptr++;
}
inline int read_int() {
  int sg = +1, ch;
  do {
    ch = read_char();
    if (ch == '-') sg = -1;
  } while (ch < '0' || ch > '9');
  int x = ch - '0';
  while (true) {
    ch = read_char();
    if (ch < '0' || ch > '9') break;
    x = x * 10 + ch - '0';
  }
  return sg * x;
}
void _R(int &x) { x = read_int(); }
void R() {}
template <class T, class... U>
void R(T &head, U &...tail) {
  _R(head);
  R(tail...);
}
template <class T>
void _W(const T &x) {
  cout << x;
}
void _W(const int &x) { printf("%d", x); }
void _W(const int64_t &x) { printf("%" PRId64, x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template <class T>
void _W(const vector<T> &x) {
  for (auto i = x.begin(); i != x.end(); _W(*i++))
    if (i != x.cbegin()) putchar(' ');
}
void W() {}
template <class T, class... U>
void W(const T &head, const U &...tail) {
  _W(head);
  putchar(sizeof...(tail) ? ' ' : '\n');
  W(tail...);
}
template <class T, class F = less<T>>
void sort_uniq(vector<T> &v, F f = F()) {
  sort(begin(v), end(v), f);
  v.resize(unique(begin(v), end(v)) - begin(v));
}
template <class T>
inline T bit(T x, int i) {
  return (x >> i) & 1;
}
template <class T>
inline bool chkmax(T &a, const T &b) {
  return b > a ? a = b, true : false;
}
template <class T>
inline bool chkmin(T &a, const T &b) {
  return b < a ? a = b, true : false;
}
template <class T>
using MaxHeap = priority_queue<T>;
template <class T>
using MinHeap = priority_queue<T, vector<T>, greater<T>>;
namespace FastIO {
char bo[1 << 16], *po = bo;
void flush() {
  fwrite(bo, po - bo, 1, stdout);
  po = bo;
}
void write_char(char c) {
  *po++ = c;
  if (po == end(bo)) flush();
}
}  // namespace FastIO
using FastIO::flush;
using FastIO::write_char;
void print_int(int x) {
  if (x == 0) {
    write_char('0');
    return;
  }
  char buf[16], *ed = buf;
  while (x != 0) {
    *ed++ = x % 10;
    x /= 10;
  }
  while (ed != buf) {
    write_char(*--ed + '0');
  }
}
const int N = 1e5 + 10;
int n, m;
float __attribute__((aligned(64))) a[N];
void __attribute__((noinline)) solve1(int l, int r, int x) {
  for (int i = (l); i <= int(r); i++)
    if (a[i] > x) a[i] -= x;
}
int __attribute__((noinline)) solve2(int l, int r, int x) {
  int ans = 0;
  for (int i = (l); i <= int(r); i++) ans += (a[i] == x);
  return ans;
}
void main() {
  R(n, m);
  for (int i = (1); i <= int(n); i++) a[i] = read_int();
  for (int mi = 0; mi < int(m); mi++) {
    int op, l, r;
    R(op, l, r);
    float x = read_int();
    if (op == 1) {
      solve1(l, r, x);
    } else {
      int ans = solve2(l, r, x);
      print_int(ans);
      write_char('\n');
    }
  }
  flush();
}
}  // namespace shik
}  // namespace
int main() {
  shik::main();
  return 0;
}
