#include <bits/stdc++.h>
using namespace std;
struct node {
  int t, x, y, z;
} d[300007], tmp[1500007];
struct tree {
  int t[600017], tot;
  int add(int x, int v) {
    x += 300005;
    while (x <= 600005) t[x] += v, x += x & -x;
    tot += v;
    return 0;
  }
  int ask(int x) {
    x += 300005;
    int res = 0;
    while (x) res += t[x], x -= x & -x;
    return res;
  }
} t[3];
int num, n, q, cnt, res[300007];
int read() {
  int num = 0;
  char c = getchar();
  while (c < '0' || c > '9') c = getchar();
  while (c >= '0' && c <= '9') num = num * 10 + c - '0', c = getchar();
  return num;
}
int add(int l, int r, int x, int y, int z) {
  tmp[++cnt] = node{x, l, y, z};
  tmp[++cnt] = node{x, r + 1, y, -z};
  return 0;
}
int cmp(node a, node b) {
  if (a.x == b.x) return a.t > b.t;
  return a.x < b.x;
}
int solve(int l, int r) {
  if (l == r) return 0;
  int mid = (l + r) / 2;
  solve(l, mid);
  solve(mid + 1, r);
  cnt = 0;
  for (int i = l; i <= mid; i++) {
    if (d[i].t == 1) {
      add(d[i].x, d[i].x + d[i].z, 0, d[i].y, 1);
      add(d[i].x, d[i].x + d[i].z, 1, d[i].x + d[i].y + d[i].z + 1, -1);
    }
    if (d[i].t == 2) {
      add(d[i].x, d[i].x + d[i].z, 2, d[i].y - d[i].x - d[i].z, 1);
      add(d[i].x, d[i].x + d[i].z, 0, d[i].y + 1, -1);
    }
    if (d[i].t == 3) {
      add(d[i].x - d[i].z, d[i].x, 0, d[i].y, 1);
      add(d[i].x - d[i].z, d[i].x, 2, d[i].y - d[i].x + d[i].z + 1, -1);
    }
    if (d[i].t == 4) {
      add(d[i].x - d[i].z, d[i].x, 1, d[i].x + d[i].y - d[i].z, 1);
      add(d[i].x - d[i].z, d[i].x, 0, d[i].y + 1, -1);
    }
  }
  for (int i = mid + 1; i <= r; i++)
    if (!d[i].t) tmp[++cnt] = node{-d[i].z, d[i].x, d[i].y, 0};
  sort(tmp + 1, tmp + cnt + 1, cmp);
  for (int i = 1; i <= cnt; i++)
    if (tmp[i].t >= 0)
      t[tmp[i].t].add(tmp[i].y, tmp[i].z);
    else {
      res[-tmp[i].t] += t[0].ask(tmp[i].y);
      res[-tmp[i].t] += t[1].ask(tmp[i].x + tmp[i].y);
      res[-tmp[i].t] += t[2].ask(tmp[i].y - tmp[i].x);
    }
  return 0;
}
int main() {
  n = read();
  q = read();
  for (int i = 1; i <= q; i++) {
    int tp = read();
    if (tp == 1) {
      d[i].t = read();
      d[i].x = read();
      d[i].y = read();
      d[i].z = read();
    } else {
      d[i].x = read();
      d[i].y = read();
      d[i].z = ++cnt;
    }
  }
  int tot = cnt;
  solve(1, q);
  for (int i = 1; i <= tot; i++) printf("%d\n", res[i]);
  return 0;
}
