题解:

和上一题差不多

就加上一个初始值

代码:

#include<bits/stdc++.h>
const int N=;
using namespace std;
int n,m,cnt,s,sum[N],ans1[N],pos[N],ans[N];
struct date{int op,x,y,v,id;}qs[N];
int comp(date x,date y){return x.x<y.x;}
void add(int x,int y){for (int i=x;i<=n;i+=i&-i)sum[i]+=y;}
int query(int x)
{
int temp=;
for (int i=x;i;i-=i&-i)temp+=sum[i];
return temp;
}
void solve(int l,int r)
{
if (l==r) return;
int mid=(l+r)/,temp=;
solve(l,mid);solve(mid+,r);
sort(qs+l,qs+mid+,comp);
sort(qs+mid+,qs+r+,comp);
int i=l,j=mid+;
while (j<=r)
{
while (qs[i].op==&&i<=mid) i++;
while (qs[j].op==&&j<=r) j++;
if (i<=mid&&qs[i].x<=qs[j].x) add(qs[i].y,qs[i].v),i++,temp=i-;
else if (j<=r) ans[qs[j].id]+=query(qs[j].y),j++;
}
for (int t=l;t<=temp;t++) if (qs[t].op==) add(qs[t].y,-qs[t].v);
}
int main()
{
memset(ans,,sizeof(ans));
memset(sum,,sizeof(sum));
int op,x1,x2,y1,y2;
scanf("%d%d",&s,&n),m=cnt=;
for (;;)
{
scanf("%d",&op);
if (op==)
{
qs[++m].op=op,qs[m].id=m;
scanf("%d%d%d",&qs[m].x,&qs[m].y,&qs[m].v);
}
else
{
if (op==)
{
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
pos[++cnt]=m;
qs[++m].op=op,qs[m].x=x1-,qs[m].y=y1-,qs[m].id=m;
ans1[m]+=s*(x2-x2+)*(y2-y1+);
qs[++m].op=op,qs[m].x=x2,qs[m].y=y2,qs[m].id=m;
qs[++m].op=op,qs[m].x=x1-,qs[m].y=y2,qs[m].id=m;
qs[++m].op=op,qs[m].x=x2,qs[m].y=y1-,qs[m].id=m;
}
else break;
}
}
solve(,m);
for (int i=;i<=cnt;i++)
printf("%d\n",ans[pos[i]+]+ans[pos[i]+]-ans[pos[i]+]-ans[pos[i]+]);
}
05-08 08:08