#include <bits/stdc++.h>
using namespace std;
namespace IO {
const int SIZE = 1 << 20;
char buf[SIZE + 10], *iS, *iT;
inline char Getc() {
  return iS == iT && (iT = (iS = buf) + fread(buf, 1, SIZE, stdin), iS == iT)
             ? EOF
             : *iS++;
}
template <class TT>
inline void Read(TT &x) {
  x = 0;
  register char cc = '\0';
  TT fff = 1;
  for (; cc < '0' || cc > '9'; cc = Getc())
    if (cc == '-') fff = -1;
  for (; cc >= '0' && cc <= '9'; cc = Getc())
    x = (x << 1) + (x << 3) + (cc & 15);
  x *= fff;
}
}  // namespace IO
using IO::Read;
const int U = 5088, N = 1e5 + 10;
struct BIT {
  int Tree[U + 10];
  inline void Update(int x, int ad) {
    for (int i = x; i; i -= i & -i) Tree[i] += ad;
  }
  inline int Query(int x) {
    int fsum = 0;
    for (int i = x; i <= U; i += i & -i) fsum += Tree[i];
    return fsum;
  }
} ta, tb;
struct asknode {
  int tm, dir, x, y, alen;
} ak[N];
struct qrynode {
  int tp, x, y, dis, ad;
  inline void Getdis(int z) { dis = x + y + z; }
  bool operator<(const qrynode &Other) const {
    return dis == Other.dis ? tp > Other.tp : dis < Other.dis;
  }
} b[2 * N], c[2 * N];
bool mk[2 * N];
int n, q, cnt, fans[N];
void Solve(int nl, int nr) {
  if (nl == nr) return;
  int nm = (nl + nr) >> 1;
  Solve(nl, nm), Solve(nm + 1, nr);
  int i = nl, j = nm + 1, k = nl;
  for (k = nl; k <= nr; ++k)
    if ((i <= nm && b[i] < b[j]) || j > nr)
      c[k] = b[i++], mk[k] = false;
    else
      c[k] = b[j++], mk[k] = true;
  int qans = 0;
  for (k = nl; k <= nr; ++k) {
    if (!c[k].tp && mk[k]) {
      fans[c[k].ad] += qans - (ta.Query(c[k].x) + tb.Query(c[k].y));
    }
    if (c[k].tp && !mk[k]) {
      qans += c[k].ad;
      ta.Update(c[k].x - 1, c[k].ad);
      tb.Update(c[k].y - 1, c[k].ad);
    }
  }
  for (k = nl; k <= nr; ++k) {
    b[k] = c[k];
    if (c[k].tp && !mk[k]) {
      ta.Update(c[k].x - 1, -c[k].ad);
      tb.Update(c[k].y - 1, -c[k].ad);
    }
  }
}
int main() {
  Read(n), Read(q);
  for (int i = 1, op; i <= q; ++i) {
    Read(op);
    ak[i].tm = i;
    if (op == 1) {
      Read(ak[i].dir);
      Read(ak[i].x), Read(ak[i].y), Read(ak[i].alen);
    } else {
      ak[i].dir = 0;
      Read(ak[i].x), Read(ak[i].y);
    }
  }
  cnt = 0;
  for (int i = 1; i <= q; ++i)
    if (ak[i].dir == 0 || ak[i].dir == 1) {
      b[++cnt] = (qrynode){(ak[i].dir ? 1 : 0), ak[i].x, ak[i].y, 0,
                           (ak[i].dir ? 1 : ak[i].tm)};
      b[cnt].Getdis(0);
      if (ak[i].dir) {
        b[++cnt] = (qrynode){(ak[i].dir ? 1 : 0), ak[i].x, ak[i].y, 0,
                             (ak[i].dir ? -1 : ak[i].tm)};
        b[cnt].Getdis(ak[i].alen + 1);
      }
    }
  Solve(1, cnt);
  cnt = 0;
  for (int i = 1; i <= q; ++i)
    if (ak[i].dir == 0 || ak[i].dir == 2) {
      b[++cnt] = (qrynode){(ak[i].dir ? 1 : 0), ak[i].x, n - ak[i].y + 1, 0,
                           (ak[i].dir ? 1 : ak[i].tm)};
      b[cnt].Getdis(0);
      if (ak[i].dir) {
        b[++cnt] = (qrynode){(ak[i].dir ? 1 : 0), ak[i].x, n - ak[i].y + 1, 0,
                             (ak[i].dir ? -1 : ak[i].tm)};
        b[cnt].Getdis(ak[i].alen + 1);
      }
    }
  Solve(1, cnt);
  cnt = 0;
  for (int i = 1; i <= q; ++i)
    if (ak[i].dir == 0 || ak[i].dir == 3) {
      b[++cnt] = (qrynode){(ak[i].dir ? 1 : 0), n - ak[i].x + 1, ak[i].y, 0,
                           (ak[i].dir ? 1 : ak[i].tm)};
      b[cnt].Getdis(0);
      if (ak[i].dir) {
        b[++cnt] = (qrynode){(ak[i].dir ? 1 : 0), n - ak[i].x + 1, ak[i].y, 0,
                             (ak[i].dir ? -1 : ak[i].tm)};
        b[cnt].Getdis(ak[i].alen + 1);
      }
    }
  Solve(1, cnt);
  cnt = 0;
  for (int i = 1; i <= q; ++i)
    if (ak[i].dir == 0 || ak[i].dir == 4) {
      b[++cnt] = (qrynode){(ak[i].dir ? 1 : 0), n - ak[i].x + 1,
                           n - ak[i].y + 1, 0, (ak[i].dir ? 1 : ak[i].tm)};
      b[cnt].Getdis(0);
      if (ak[i].dir) {
        b[++cnt] = (qrynode){(ak[i].dir ? 1 : 0), n - ak[i].x + 1,
                             n - ak[i].y + 1, 0, (ak[i].dir ? -1 : ak[i].tm)};
        b[cnt].Getdis(ak[i].alen + 1);
      }
    }
  Solve(1, cnt);
  for (int i = 1; i <= q; ++i)
    if (!ak[i].dir) printf("%d\n", fans[i]);
  return 0;
}
