#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("avx")
using namespace std;
int a[100010];
int main() {
  ios::sync_with_stdio(false);
  int n, m;
  scanf("%d%d", &n, &m);
  for (register int i = 1; i <= n; ++i) scanf("%d", &a[i]);
  int ty, l, r, A;
  float x;
  while (m--) {
    scanf("%d%d%d%f", &ty, &l, &r, &x);
    if (ty == 1)
      for (register int i = l; i <= r; ++i) a[i] -= (a[i] > x ? x : 0);
    else {
      A = 0;
      for (register int i = l; i <= r; ++i)
        if (a[i] == x) ++A;
      printf("%d\n", A);
    }
  }
  return 0;
}
