#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector,-fomit-frame-pointer")
#pragma GCC target("avx")
using namespace std;
int main(void) {
  register int i, count;
  int n, m, l, r, t;
  float x;
  scanf("%d %d", &n, &m);
  int a[100003];
  for (i = 1; i <= n; ++i) scanf("%d", &a[i]);
  while (m--) {
    scanf("%d %d %d %f", &t, &l, &r, &x);
    if (t == 1) {
      for (i = l; i <= r; ++i) {
        if (a[i] > x) a[i] -= x;
      }
    } else {
      count = 0;
      for (i = l; i <= r; ++i) {
        if (a[i] == x) ++count;
      }
      printf("%d\n", count);
    }
  }
  return 0;
}
