/************************************************************** Problem: 1176 User: syh0313 Language: C++ Result: Accepted Time:13364 ms Memory:158344 kb ****************************************************************/ #include <iostream> #include <cstdio> #include <cstdlib> #include <algorithm> #include <cmath> using namespace std; const int maxn=100010; int w,n,cnt,opt,x,xx,y,yy; long long s,ans[maxn],vv,a[50*maxn]; struct da{ int op,x,y; long long v; int id;}q[50*maxn]; bool cmp(da aa,da bb){ return aa.x<bb.x;} inline int lowbit( int x){ return x&(-x);} void add( int x, long long k){ while (x<=w+1) {a[x]+=k; x+=lowbit(x);}} long long qury( int x){ long long sum=0; while (x) {sum+=a[x]; x-=lowbit(x);} return sum;} void cdq( int l, int r) { if (l==r) return ; int mid=(l+r)>>1; cdq(l,mid); sort(q+l,q+mid+1,cmp); cdq(mid+1,r); sort(q+mid+1,q+r+1,cmp); int p1=l,p2=mid+1; while (p2<=r) { while (p1<=mid && q[p1].x<=q[p2].x) { if (q[p1].op==1) add(q[p1].y,q[p1].v); p1++;} if (q[p2].op==2) ans[q[p2].id]+=qury(q[p2].y)*q[p2].v; p2++; } p1=l; p2=mid+1; while (p2<=r) { while (p1<=mid && q[p1].x<=q[p2].x) { if (q[p1].op==1) add(q[p1].y,-q[p1].v); p1++;} p2++; } } int main() { scanf ( "%lld%d" ,&s,&w); while ( scanf ( "%d" ,&opt) && opt!=3) { if (opt==1) { scanf ( "%d%d%lld" ,&x,&y,&vv); x++; y++; q[++n]={1,x,y,vv,0};} else { scanf ( "%d%d%d%d" ,&x,&y,&xx,&yy); cnt++; x++; y++; xx++; yy++; q[++n]={2,x-1,y-1,1,cnt}; q[++n]={2,xx,yy,1,cnt}; q[++n]={2,x-1,yy,-1,cnt}; q[++n]={2,xx,y-1,-1,cnt}; } } cdq(1,n); for ( int i=1;i<=cnt;i++) printf ( "%lld\n" ,ans[i]+s); return 0; } |