#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("avx")
inline void read(int& x) {
  x = 0;
  int f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    if (ch == EOF) return;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  x *= f;
}
inline void read(short& x) {
  x = 0;
  int f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    if (ch == EOF) return;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  x *= f;
}
int a[100002];
int main() {
  int n, m, ans, l, r;
  short T;
  float x;
  read(n);
  read(m);
  for (register int i = 1; i <= n; ++i) read(a[i]);
  while (m--) {
    read(T);
    read(l);
    read(r);
    scanf("%f", &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;
}
