看起来完全不可做的一道题qwq,cdq强行优化为 O(nlogn2)
一个query分成4个
然后时间这一维本来就有序,分治时对x排序,y上用BIT维护前缀和。
另:s好像没用
//QWsin
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn=200000+10;
const int maxw=2000000+10;
int s,w,opcnt;
struct OP{
int k,a,b,c,id,t,flag;OP(){}
OP(int k,int a,int b,int id,int f,int t):k(k),a(a),b(b),id(id),t(t),flag(f){}
OP(int k,int a,int b,int c,int id):k(k),a(a),b(b),c(c),id(id){}
inline bool operator < (const OP &rhs)const{
return a<rhs.a||(a==rhs.a&&(b<rhs.b||(b==rhs.b&&t<rhs.t)));
}
}a[maxn],t[maxn];
int is_q[maxn];
/******BIT******/
int C[maxw];
#define lowbit(i) ((i)&-(i))
inline void updata(int pos,int val){
for(int i=pos;i<=w;i+=lowbit(i)) C[i]+=val;
}
inline int query(int pos){
int ret=0;
for(int i=pos;i;i-=lowbit(i)) ret+=C[i];
return ret;
}
int ans[maxn];
void solve(int l,int r)
{
if(l==r) return ;
int mid=(l+r)>>1;
solve(l,mid);solve(mid+1,r);
//t[i].t==1表示在右边
for(int i=l;i<=r;++i) t[i]=a[i],t[i].t=(i>mid?1:0);
sort(t+l,t+r+1);
for(int i=l;i<=r;++i)
{
if(t[i].id==6){
int stop=1;
}
if(t[i].k==1&&t[i].t==0)
updata(t[i].b,t[i].c);
if(t[i].k==2&&t[i].t==1)
ans[t[i].id]+=query(t[i].b)*t[i].flag;
}
for(int i=l;i<=r;++i) if(t[i].k==1&&t[i].t==0) updata(t[i].b,-t[i].c);
}
int main()
{
cin>>s>>w;
int k,A,b,c,d,t;
for(t=1;;++t){
scanf("%d",&k);
if(k==3) break;
if(k==1)
{
scanf("%d%d%d",&A,&b,&c);
a[++opcnt]=OP(k,A,b,c,t);
}
else
{
is_q[t]=1;
scanf("%d%d%d%d",&A,&b,&c,&d);
// ans[t]+=(A-c)*(d-b)*s;
a[++opcnt]=OP(k,c,d,t,1,0);
a[++opcnt]=OP(k,c,b-1,t,-1,0);
a[++opcnt]=OP(k,A-1,d,t,-1,0);
a[++opcnt]=OP(k,A-1,b-1,t,1,0);
}
}
solve(1,opcnt);
for(int i=1;i<=t;++i) if(is_q[i]) printf("%d\n",ans[i]);
return 0;
}