#include <bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
const int MAXN = 1e5 + 5;
int n, m;
int a[MAXN];
int main() {
  register int i, j, s = 0;
  scanf("%d %d", &n, &m);
  for (i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  register int t, l, r;
  float x;
  for (i = 1; i <= m; i++) {
    scanf("%d", &t);
    scanf("%d %d %f", &l, &r, &x);
    if (t == 1) {
      for (j = l; j <= r; j++) {
        a[j] -= (a[j] > x) ? x : 0;
      }
    } else {
      for (j = l; j <= r; j++) {
        s += (a[j] == x);
      }
      printf("%d\n", s);
      s = 0;
    }
  }
  return 0;
}
