#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("avx")
int a[100002], n, m, ans, T, l, r, x;
int main() {
  scanf("%d%d", &n, &m);
  for (register int i = 1; i <= n; ++i) scanf("%d", &x);
  while (m--) {
    scanf("%d%d%d%d", &T, &l, &r, &x);
    if (T == 1) {
      for (register int i = l; i <= r; ++i) a[i] -= a[i] > x ? x : 0;
    } else {
      ans = 0;
      for (register int i = l; i <= r; ++i) a[i] == x ? ++ans : 0;
      printf("%d\n", ans);
    }
  }
  return 0;
}
