题目这么说的:

这篇题解写得挺详细的:http://wulala.logdown.com/posts/207262-boi-2007-mokia

。。然后感觉这题转化成二维前缀和的差分挺厉害的。

 #include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std; long long tree[<<];
int N,x,y;
void update(int i,int j,int k){
if(i==j){
tree[k]+=y;
return;
}
int mid=i+j>>;
if(x<=mid) update(i,mid,k<<);
else update(mid+,j,k<<|);
tree[k]=tree[k<<]+tree[k<<|];
}
long long query(int i,int j,int k){
if(x>y) return ;
if(x<=i && j<=y){
return tree[k];
}
int mid=i+j>>;
long long res=;
if(x<=mid) res+=query(i,mid,k<<);
if(y>mid) res+=query(mid+,j,k<<|);
return res;
} struct Query{
int idx,type,anspos;
int x,y,A;
bool operator<(const Query &q) const {
return x<q.x;
}
}que[],tmp[]; long long ans[]; void cdq(int l,int r){
if(l>=r) return;
int mid=l+r>>,i=l,j=mid+;
for(int k=l; k<=r; ++k){
if(que[k].idx<=mid) tmp[i++]=que[k];
else tmp[j++]=que[k];
}
for(int k=l; k<=r; ++k){
que[k]=tmp[k];
} for(i=mid+,j=l; i<=r; ++i){
if(que[i].type==) continue;
for( ; j<=mid && que[j].x<=que[i].x; ++j){
if(que[j].type==) continue;
x=que[j].y; y=que[j].A;
update(,N,);
}
x=; y=que[i].y;
ans[que[i].anspos]+=query(,N,)*que[i].A;
} for(int i=l; i<j; ++i){
if(que[i].type==) continue;
x=que[i].y; y=-que[i].A;
update(,N,);
} cdq(l,mid); cdq(mid+,r);
} int main(){
//freopen("mokia.in","r",stdin); freopen("mokia.out","w",stdout); int op,n,a,b,c,d;
scanf("%d%d",&op,&n);
int opn=,cnt=;
while(scanf("%d",&op),op!=){
if(op==){
scanf("%d%d%d",&a,&b,&c);
que[++opn].idx=opn; que[opn].type=; que[opn].x=a; que[opn].y=b; que[opn].A=c;
}else if(op==){
scanf("%d%d%d%d",&a,&b,&c,&d);
++cnt;
que[++opn].idx=opn; que[opn].type=; que[opn].anspos=cnt; que[opn].x=c; que[opn].y=d; que[opn].A=;
que[++opn].idx=opn; que[opn].type=; que[opn].anspos=cnt; que[opn].x=c; que[opn].y=b-; que[opn].A=-;
que[++opn].idx=opn; que[opn].type=; que[opn].anspos=cnt; que[opn].x=a-; que[opn].y=d; que[opn].A=-;
que[++opn].idx=opn; que[opn].type=; que[opn].anspos=cnt; que[opn].x=a-; que[opn].y=b-; que[opn].A=;
}
} for(N=; N<n; N<<=); sort(que+,que++opn);
cdq(,opn); for(int i=; i<=cnt; ++i){
printf("%lld\n",ans[i]);
}
return ;
}
05-07 15:06