#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#pragma GCC target( \
    "sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,avx2,popcnt,tune=native")
using namespace std;
inline int read() {
  int x = 0, ch;
  while (!isdigit(ch = getchar()))
    ;
  while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
  return x;
}
const int MAXN = 100000;
int n;
int m;
int a[MAXN + 1];
int main() {
  n = read(), m = read();
  for (int i = 1; i <= n; i++) a[i] = read();
  while (m--) {
    int opt = read(), l = read(), r = read(), x = read();
    if (opt & 1)
      for (int i = l; i <= r; ++i) a[i] -= a[i] > x ? x : 0;
    else {
      int s = 0;
      for (int i = l; i <= r; i++) s += a[i] == x;
      printf("%d\n", s);
    }
  }
  return 0;
}
