#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("avx")
float a[100002];
int main() {
  int n, m, ans, l, r;
  short T;
  float x;
  scanf("%d%d", &n, &m);
  for (register int i = 1; i <= n; ++i) scanf("%f", &a[i]);
  while (m--) {
    scanf("%hd%d%d%f", &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;
}
