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