#include <bits/stdc++.h>
int main() {
  int i, j, count, n, m;
  char str[700000];
  scanf("%d %d\n", &n, &m);
  int a[n];
  int ope[m][4];
  fgets(str, 700000, stdin);
  int str_index, buf_index = 0, n_count = 0;
  char buf[7] = {0};
  for (str_index = 0; n_count < n; str_index++) {
    if (str[str_index] == ' ') {
      a[n_count++] = atoi(buf);
      memset(buf, '\0', 10);
      buf_index = 0;
    } else if (str[str_index] == '\0') {
      a[n_count++] = atoi(buf);
      break;
    } else {
      buf[buf_index++] = str[str_index];
    }
  }
  for (i = 0; i < m; i++) {
    scanf("%d %d %d %d", &ope[i][0], &ope[i][1], &ope[i][2], &ope[i][3]);
  }
  for (i = 0; i < m; i++) {
    if (ope[i][0] == 1) {
      for (j = ope[i][1] - 1; j < ope[i][2]; j++) {
        a[j] -= ope[i][3] * (ope[i][3] < a[j]);
      }
    } else {
      count = 0;
      for (j = ope[i][1] - 1; j < ope[i][2]; j++) {
        count += (ope[i][3] == a[j]);
      }
      printf("%d\n", count);
    }
  }
}
