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