//cogs 577 蝗灾
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#define ll long long
#define M(a) memset(a,0,sizeof a)
#define fo(i,j,k) for(i=j;i<=k;i++)
using namespace std;
const int mxn=800005;
int tot,n,m,T,id;
int c[mxn],t[mxn],ans[mxn];
inline int lowbit(int x) {return x&-x;}
inline void add(int x,int v) {for(int i=x;i<=n;i+=lowbit(i)) c[i]+=v;}
inline int getsum(int x) {int sum=0;for(int i=x;i>=1;i-=lowbit(i)) sum+=c[i];return sum;}
struct query
{
int x,y,f,opt,be,id;
}q[mxn],tmp[mxn];
inline bool comp(query a,query b)
{
if(a.x==b.x && a.y==b.y) return a.be<b.be;
if(a.x==b.x) return a.y<b.y;
return a.x<b.x;
}
inline void CDQ(int l,int r)
{
int i,j,mid=l+r>>1,l1=l,l2=mid+1;
if(l==r) return;
fo(i,l,r)
{
if(q[i].id<=mid && q[i].opt==1) add(q[i].y,q[i].f);
if(q[i].id>mid && q[i].opt==2) ans[q[i].be]+=q[i].f*getsum(q[i].y);
}
fo(i,l,r) if(q[i].id<=mid && q[i].opt==1) add(q[i].y,-q[i].f);
fo(i,l,r)
if(q[i].id<=mid) tmp[l1++]=q[i];
else tmp[l2++]=q[i];
fo(i,l,r) q[i]=tmp[i];
CDQ(l,mid),CDQ(mid+1,r);
}
int main()
{
freopen("locust.in","r",stdin);
freopen("locust.out","w",stdout);
int i,j,x1,y1,x2,y2,opt;
scanf("%d%d",&n,&m);
fo(i,1,m)
{
scanf("%d",&opt);
if(opt==1) q[++tot].opt=1,scanf("%d%d%d",&q[tot].x,&q[tot].y,&q[tot].f),q[tot].be=i,q[tot].id=++id;
else
{
t[i]=1;
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
q[++tot].opt=2,q[tot].x=x1-1,q[tot].y=y1-1,q[tot].f=1,q[tot].be=i,q[tot].id=++id;
q[++tot].opt=2,q[tot].x=x2,q[tot].y=y1-1,q[tot].f=-1,q[tot].be=i,q[tot].id=++id;
q[++tot].opt=2,q[tot].x=x1-1,q[tot].y=y2,q[tot].f=-1,q[tot].be=i,q[tot].id=++id;
q[++tot].opt=2,q[tot].x=x2,q[tot].y=y2,q[tot].f=1,q[tot].be=i,q[tot].id=++id;
}
}
sort(q+1,q+tot+1,comp);
CDQ(1,tot);
fo(i,1,m) if(t[i]) printf("%d\n",ans[i]);
return 0;
}