#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
const int maxn = 100010;
int n, m, a[maxn];
void print(int x) {
  if (x >= 10) print(x / 10);
  putchar(x % 10 + '0');
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  for (int i = 1, op, l, r, x; i <= m; i++) {
    scanf("%d %d %d %d", &op, &l, &r, &x);
    if (op == 1) {
      int j = l;
      int *b = a + l;
      for (; j + 7 <= r; j += 8) {
        *b -= *b > x ? x : 0, b++;
        *b -= *b > x ? x : 0, b++;
        *b -= *b > x ? x : 0, b++;
        *b -= *b > x ? x : 0, b++;
        *b -= *b > x ? x : 0, b++;
        *b -= *b > x ? x : 0, b++;
        *b -= *b > x ? x : 0, b++;
        *b -= *b > x ? x : 0, b++;
      }
      while (j <= r) {
        a[j] -= a[j] > x ? x : 0, j++;
      }
    } else {
      int ans = 0, j = l;
      int *b = a + l;
      for (; j + 7 <= r; j += 8) {
        ans += *b == x, b++;
        ans += *b == x, b++;
        ans += *b == x, b++;
        ans += *b == x, b++;
        ans += *b == x, b++;
        ans += *b == x, b++;
        ans += *b == x, b++;
        ans += *b == x, b++;
      }
      while (j <= r) {
        ans += a[j] == x, j++;
      }
      print(ans), putchar('\n');
    }
  }
  return 0;
}
