Butterfly__qwq @ 2024-02-19 10:37:50
/*
Author:qhzx_FeS2_Butterfly
Start Coding:2024/2/17 12:45
Finish Coding:2024/2/17 13:55
Finish Debugging:2024
*/
#include<bits/stdc++.h>
using namespace std;
constexpr int Q=200005,L=18;
struct node
{
int x[2],w,sum,lc,rc,mn[2],mx[2];
}kdt[Q],lu,rd;
int n,flr,rt[L],per[Q];
void pushup(int u)
{
kdt[u].sum=kdt[kdt[u].lc].sum+kdt[kdt[u].rc].sum+kdt[u].w;
for(int i:{0,1})
{
kdt[u].mn[i]=kdt[u].mx[i]=kdt[u].x[i];
if(kdt[u].lc)
{
kdt[u].mn[i]=min(kdt[u].mn[i],kdt[kdt[u].lc].mn[i]);
kdt[u].mx[i]=max(kdt[u].mx[i],kdt[kdt[u].lc].mx[i]);
}
if(kdt[u].rc)
{
kdt[u].mn[i]=min(kdt[u].mn[i],kdt[kdt[u].rc].mn[i]);
kdt[u].mx[i]=max(kdt[u].mx[i],kdt[kdt[u].rc].mx[i]);
}
}
}
void append(int &u)
{
if(!u)return;
per[++flr]=u;
append(kdt[u].lc);
append(kdt[u].rc);
u=0;
}
int build(int l,int r,int dms)
{
int mid=l+r>>1;
nth_element(per+l,per+mid,per+r+1,[dms](int a,int b){return kdt[a].x[dms]<kdt[b].x[dms];});
int root=per[mid];
if(l<mid)build(l,mid-1,dms^1);
if(r>mid)build(mid+1,r,dms^1);
pushup(root);
return root;
}
int query(int u)
{
if(!u)return 0;
int f=1;
for(int i:{0,1})f&=(lu.x[i]<=kdt[u].mn[i]&&rd.x[i]>=kdt[u].mx[i]);
if(f)return kdt[u].sum;
for(int i:{0,1})if(kdt[u].mx[i]<lu.x[i]||kdt[u].mn[i]>rd.x[i])return 0;
int ans=0;f=1;
for(int i:{0,1})f&=(lu.x[i]<=kdt[u].x[i]&&rd.x[i]>=kdt[u].x[i]);
if(f)ans=kdt[u].w;
ans+=query(kdt[u].lc)+query(kdt[u].rc);
return ans;
}
int main()
{
cin>>n;n=0;
int last_ans=0;
for(;;)
{
int op;
cin>>op;
if(op==1)
{
int x,y,a;
cin>>x>>y>>a;
x^=last_ans;y^=last_ans;a^=last_ans;
kdt[++n]={{x,y},a};
per[flr=1]=n;
for(int i=0;;i++)
{
if(rt[i])append(rt[i]);
else
{
rt[i]=build(1,flr,0);
break;
}
}
}
else if(op==2)
{
cin>>lu.x[0]>>lu.x[1]>>rd.x[0]>>rd.x[1];
lu.x[0]^=last_ans;lu.x[1]^=last_ans;rd.x[0]^=last_ans;rd.x[1]^=last_ans;
last_ans=0;
for(int i=0;i<L;i++)last_ans+=query(rt[i]);
cout<<last_ans<<'\n';
}
else return 0;
}
}
码丑轻喷/kk
by ZYLZPP @ 2024-04-03 13:05:59
if(l<mid)build(l,mid-1,dms^1);
if(r>mid)build(mid+1,r,dms^1);
此处未对kdt[root]左右儿子赋值
可以改成
kdt[root].ls = l<mid? build(l,mid-1,dms^1): 0;
kdt[root].rs = mid<r? build(mid+1,r,dms^1): 0;