#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void rd(T &x) {
  x = 0;
  char c = getchar();
  int f = 1;
  while (!isdigit(c)) {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (isdigit(c)) x = x * 10 - '0' + c, c = getchar();
  x *= f;
}
int a[5010][10050], n, m;
void add(int x, int y, int t) {
  if (x < 0 || y < 0) return;
  for (int i = x; i; i -= i & -i)
    for (int j = y; j; j -= j & -j) a[i][j] += t;
}
int query(int x, int y) {
  int ans = 0;
  for (int i = x; i <= n; i += i & -i)
    for (int j = y; j <= m; j += j & -j) ans += a[i][j];
  return ans;
}
struct item {
  int p, l, r, y, t;
};
vector<item> D[3];
int Qt[100010], Qx[100010], Qy[100010], ans[100010], Q, q;
int main() {
  rd(n), rd(q);
  for (int i = 1, op, x, y, len, dir; i <= q; ++i) {
    rd(op);
    if (op == 1) {
      rd(dir), rd(x), rd(y), rd(len);
      item A, B;
      if (dir <= 2)
        A.l = B.l = x, A.r = B.r = x + len;
      else
        A.l = B.l = x - len, A.r = B.r = x;
      A.p = B.p = i;
      if (dir == 1) {
        B.y = x + y + len, B.t = 1;
        D[1].push_back(B);
        A.y = y - 1, A.t = -1;
        D[0].push_back(A);
      } else if (dir == 2) {
        B.y = y - x - len - 1, B.t = -1;
        D[2].push_back(B);
        A.y = y, A.t = 1;
        D[0].push_back(A);
      } else if (dir == 3) {
        B.y = y - x + len, B.t = 1;
        D[2].push_back(B);
        A.y = y - 1, A.t = -1;
        D[0].push_back(A);
      } else {
        B.y = x + y - len - 1, B.t = -1;
        D[1].push_back(B);
        A.y = y, A.t = 1;
        D[0].push_back(A);
      }
    } else {
      Q++;
      Qt[Q] = i;
      rd(Qx[Q]), rd(Qy[Q]);
    }
  }
  for (int c = 0; c < 3; ++c) {
    memset(a, 0, sizeof(a));
    const int B = (c == 2 ? n + 1 : 0);
    m = c == 0 ? n : 2 * n;
    int cur = 1;
    while (D[c].size() && cur <= Q && D[c][0].p > Qt[cur]) cur++;
    for (int i = 0; i < D[c].size(); ++i) {
      add(D[c][i].l - 1, D[c][i].y + B, -D[c][i].t);
      add(D[c][i].r, D[c][i].y + B, D[c][i].t);
      while (cur <= Q && (i + 1 == D[c].size() || D[c][i + 1].p > Qt[cur])) {
        int x = Qx[cur], y = Qy[cur];
        if (c == 1) y = x + y;
        if (c == 2) y = y - x;
        ans[cur] += query(x, y + B);
        cur++;
      }
    }
  }
  for (int i = 1; i <= Q; ++i) printf("%d\n", ans[i]);
  return 0;
}
