#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;
const int N = 1e5 + 5;
int n, m, a[N];
float x;
int main() {
  scanf("%d%d", &n, &m);
  for (register int i = 1; i <= n; i++) scanf("%d", &a[i]);
  while (m--) {
    register int op, l, r, x, ans = 0;
    scanf("%d%d%d%f", &op, &l, &r, &x);
    if (op == 1) {
      for (int i = l; i <= r; i++) {
        a[i] -= (a[i] > x) ? x : 0;
      }
    } else {
      for (int i = l; i <= r; i++) {
        ans += (a[i] == x);
      }
      printf("%d\n", ans);
    }
  }
  return 0;
}
