#include <bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
int a[100010];
inline void read(int &x) {
  char ch = getchar();
  x = 0;
  while ((ch < '0') || (ch > '9')) ch = getchar();
  while ((ch >= '0') && (ch <= '9')) x = x * 10 + ch - '0', ch = getchar();
}
int main() {
  int n, m;
  read(n);
  read(m);
  for (int i = 1; i <= n; i++) read(a[i]);
  while (m--) {
    int tp, l, r, x;
    read(tp);
    read(l);
    read(r);
    read(x);
    if (tp == 1) {
      for (int i = l; i <= r; i++) a[i] -= (a[i] > x) ? x : 0;
    } else {
      int ans = 0, i;
      for (int i = l; i <= r; i++) ans += (a[i] == x);
      printf("%d\n", ans);
    }
  }
}
