#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma comment(linker, "/stack:200000000")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
const int N = 1e5 + 5, INF = 0x3f3f3f3f;
inline int read() {
  int x = 0, f = 0;
  char ch = 0;
  while (!isdigit(ch)) f |= ch == '-', ch = getchar();
  while (isdigit(ch)) x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar();
  return f ? -x : x;
}
int a[N];
int main() {
  int n = read(), m = read();
  for (int i = 1; i <= n; ++i) a[i] = read();
  while (m--) {
    int opt = read(), l = read(), r = read(), x = read();
    int *ap = a + l;
    int len = r - l + 1;
    if (opt == 1) {
      while (len % 4) {
        --len;
        ap[len] -= ap[len] > x ? x : 0;
      }
      len /= 4;
      while (len--) {
        ap[0] -= ap[0] > x ? x : 0;
        ap[1] -= ap[1] > x ? x : 0;
        ap[2] -= ap[2] > x ? x : 0;
        ap[3] -= ap[3] > x ? x : 0;
        ap += 4;
      }
    } else {
      int ans = 0;
      while (len % 4) {
        --len;
        ans += ap[len] == x;
      }
      len /= 4;
      while (len--) {
        ans += (ap[0] == x) + (ap[1] == x) + (ap[2] == x) + (ap[3] == x);
        ap += 4;
      }
      printf("%d\n", ans);
    }
  }
  return 0;
}
