#include <bits/stdc++.h>
using namespace std;
char gchar() {
  static char tbuf1[1000], *tmp_st = tbuf1, *tmp_ed = tbuf1;
  if (tmp_st == tmp_ed) {
    int len = fread(tbuf1, 1, 1000, stdin);
    if (len == 0) return -1;
    tmp_ed = tbuf1 + len;
    tmp_st = tbuf1;
  }
  return *(tmp_st++);
}
inline bool gn(int& x) {
  char c, sg = 0;
  while (c = gchar(), (c > '9' || c < '0') && c != '-' && ~c)
    ;
  if (c == -1) return 0;
  for ((c == '-' ? sg = 1, c = gchar() : 0), x = 0; c >= '0' && c <= '9';
       c = gchar())
    x = (x << 1) + (x << 3) + c - '0';
  if (sg) x = -x;
  return 1;
}
inline void print(int x) {
  if (x < 0) {
    putchar('-');
    return print(-x);
  }
  if (x < 10) {
    putchar('0' + x);
    return;
  }
  print(x / 10);
  putchar(x % 10 + '0');
}
template <class T>
inline void println(T x) {
  print(x);
  putchar('\n');
}
int h[100], n, m, t, l, r, st, ed, x, i, ans;
set<int> s[100][100001];
set<int>::iterator it;
int main() {
  gn(n), gn(m);
  for (i = 1; i <= n; i++) gn(x), s[x / 100][x].insert(i);
  while (m--) {
    gn(t), gn(l), gn(r), gn(x);
    if (t == 1) {
      st = l / 100, ed = r / 100;
      if (st == ed) {
        for (i = h[st] + x; i < 100001; i++) {
          for (it = s[st][i].begin(); it != s[st][i].end();) {
            t = *it++;
            if (l <= t && t <= r) s[st][i].erase(t), s[st][i - x].insert(t);
          }
        }
      } else {
        for (i = h[st] + x; i < 100001; i++) {
          while (!s[st][i].empty()) {
            it = --s[st][i].end();
            if (*it >= l) {
              s[st][i - x].insert(*it);
              s[st][i].erase(it);
            } else
              break;
          }
        }
        for (i = h[ed] + x; i < 100001; i++) {
          while (!s[ed][i].empty()) {
            it = s[ed][i].begin();
            if (*it <= r) {
              s[ed][i - x].insert(*it);
              s[ed][i].erase(it);
            } else
              break;
          }
        }
        for (t = st + 1; t < ed; t++) {
          for (i = h[t], n = min(h[t] + x, 100001 - x); i < n; i++) {
            while (!s[t][i].empty()) {
              it = --s[t][i].end();
              s[t][i + x].insert(*it);
              s[t][i].erase(it);
            }
          }
          h[t] += x;
        }
      }
    } else {
      ans = 0;
      st = l / 100, ed = r / 100;
      if (st == ed) {
        for (it = s[st][h[st] + x].begin(); it != s[st][h[st] + x].end();
             it++) {
          t = *it;
          if (l <= t && t <= r) ans++;
        }
      } else {
        for (it = s[st][h[st] + x].end();;) {
          t = *--it;
          if (t >= l)
            ans++;
          else
            break;
          if (it == s[st][h[st] + x].begin()) break;
        }
        for (it = s[ed][h[ed] + x].begin(); it != s[ed][h[ed] + x].end();
             it++) {
          t = *--it;
          if (t <= r)
            ans++;
          else
            break;
        }
        for (i = st + 1; i < ed; i++)
          if (h[i] + x < 100001) ans += s[i][h[i] + x].size();
      }
      println(ans);
    }
  }
}
