#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
float x;
static char buf[1000000], *p1 = buf, *p2 = buf;
inline int read() {
  register int x = 0;
  register char a =
      p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin), p1 == p2)
          ? EOF
          : *p1++;
  while (a < '0' || a > '9')
    a = p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin), p1 == p2)
            ? EOF
            : *p1++;
  while (a >= '0' && a <= '9')
    x = x * 10 + (a ^ 48),
    a = p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin), p1 == p2)
            ? EOF
            : *p1++;
  return x;
}
int a[100010];
int n, m;
int main() {
  n = read();
  m = read();
  for (int i = 1; i <= n; ++i) {
    a[i] = read();
  }
  for (int i = 1; i <= m; ++i) {
    int opt, l, r, x;
    opt = read();
    l = read();
    r = read();
    x = read();
    if (opt == 1) {
      for (int j = l; j <= r; ++j) {
        if (a[j] > x) a[j] -= x;
      }
    } else {
      int ans = 0;
      for (int j = l; j <= r; ++j) {
        if (a[j] == x) ++ans;
      }
      printf("%d\n", ans);
    }
  }
}
