同p1176。

#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
#define N 200011
#define KD 2//ά¶ÈÊý
int qp[2][2];
int n,root=1,m;
bool dn;
struct Node
{
int minn[KD],maxx[KD],p[KD],w,ch[2],sumv;
void Init()
{
for(int i=0;i<KD;++i)
minn[i]=maxx[i]=p[i];
sumv=w;
}
}T[N];
void Clear()
{
for(int i=1;i<=n;++i)
T[i].ch[0]=T[i].ch[1]=/*T[i].sumv=T[i].minn[0]=T[i].minn[1]=T[i].maxx[0]=T[i].maxx[1]=*/0;
}
void Update(int rt)
{
T[rt].sumv=T[rt].w;
for(int i=0;i<2;++i)
if(T[rt].ch[i])
{
T[rt].sumv+=T[T[rt].ch[i]].sumv;
for(int j=0;j<KD;++j)
{
T[rt].minn[j]=min(T[rt].minn[j],T[T[rt].ch[i]].minn[j]);
T[rt].maxx[j]=max(T[rt].maxx[j],T[T[rt].ch[i]].maxx[j]);
}
}
}
bool operator < (const Node &a,const Node &b){return a.p[dn]<b.p[dn];}
int Buildtree(int l=1,int r=n,bool d=0)
{
dn=d;
int m=(l+r>>1);
nth_element(T+l,T+m,T+r+1);
T[m].Init();
if(l!=m) T[m].ch[0]=Buildtree(l,m-1,d^1);
if(m!=r) T[m].ch[1]=Buildtree(m+1,r,d^1);
Update(m);
return m;
}
void Insert(int rt=root,bool d=0)
{
bool f=(T[n].p[d]>T[rt].p[d]);
if(T[rt].ch[f]) Insert(T[rt].ch[f],d^1);
else T[rt].ch[f]=n;
Update(rt);
}
int ans;
void Query(int rt=root)
{
if(T[rt].p[0] >= qp[0][0] && T[rt].p[0] <= qp[1][0]
&& T[rt].p[1] >= qp[0][1] && T[rt].p[1] <= qp[1][1])
ans+=T[rt].w;
for(int i=0;i<2;++i)
if(T[rt].ch[i]
&& T[T[rt].ch[i]].maxx[0] >= qp[0][0] && T[T[rt].ch[i]].minn[0] <= qp[1][0]
&& T[T[rt].ch[i]].maxx[1] >= qp[0][1] && T[T[rt].ch[i]].minn[1] <= qp[1][1])
{
if(T[T[rt].ch[i]].minn[0] >= qp[0][0] && T[T[rt].ch[i]].maxx[0] <= qp[1][0]
&& T[T[rt].ch[i]].minn[1] >= qp[0][1] && T[T[rt].ch[i]].maxx[1] <= qp[1][1])
ans+=T[T[rt].ch[i]].sumv;
else
Query(T[rt].ch[i]);
}
}
int op[N],X1[N],Y1[N],X2[N],Y2[N],Vs[N];
int main()
{
// freopen("bzoj4066.in","r",stdin);
// freopen("bzoj4066.out","w",stdout);
// for(int i=1;i<=1000000;++i);
scanf("%d",&m); m=0;
while(1)
{
++m;
scanf("%d",&op[m]);
if(op[m]==3)
{
--m;
break;
}
if(op[m]==1)
{
scanf("%d%d%d",&X1[m],&Y1[m],&Vs[m]);
++n;
}
else
scanf("%d%d%d%d",&X1[m],&Y1[m],&X2[m],&Y2[m]);
}
int blo=(int)sqrt((double)n*log2((double)n));
n=0;
for(int i=1;i<=m;++i)
{
if(op[i]==1)
{
++n;
T[n].p[0]=X1[i]; T[n].p[0]^=ans;
T[n].p[1]=Y1[i]; T[n].p[1]^=ans;
T[n].w=Vs[i]; T[n].w^=ans;
// printf("Insert%d:(%d,%d):%d\n",n,T[n].p[0],T[n].p[1],T[n].w);
T[n].Init();
if(n>1)
Insert();
if(blo==1 || blo==0 || n%blo==0)
{
Clear();
Buildtree();
root=(1+n>>1);
}
}
else
{
qp[0][0]=X1[i]; qp[0][0]^=ans;
qp[0][1]=Y1[i]; qp[0][1]^=ans;
qp[1][0]=X2[i]; qp[1][0]^=ans;
qp[1][1]=Y2[i]; qp[1][1]^=ans;
ans=0;
if(n)
Query();
printf("%d\n",ans);
}
}
}

【kd-tree】bzoj4066 简单题的更多相关文章

  1. [BZOJ2683][BZOJ4066]简单题

    [BZOJ2683][BZOJ4066]简单题 试题描述 你有一个N*N的棋盘,每个格子内有一个整数,初始时的时候全部为0,现在需要维护两种操作: 命令 参数限制 内容 1 x y A 1<=x ...

  2. bzoj4066: 简单题 K-Dtree

    bzoj4066: 简单题 链接 bzoj 思路 强制在线.k-dtree. 卡常啊.空间开1e6就T了. 代码 #include <bits/stdc++.h> #define my_m ...

  3. BZOJ4066:简单题(K-D Tree)

    Description 你有一个N*N的棋盘,每个格子内有一个整数,初始时的时候全部为0,现在需要维护两种操作:   命令 参数限制 内容 1 x y A 1<=x,y<=N,A是正整数 ...

  4. Bzoj4066 简单题

    Time Limit: 50 Sec  Memory Limit: 20 MBSubmit: 2185  Solved: 581 Description 你有一个N*N的棋盘,每个格子内有一个整数,初 ...

  5. BZOJ4066 简单题(KD-Tree)

    板子题. #include<iostream> #include<cstdio> #include<cmath> #include<cstdlib> # ...

  6. 初涉k-d tree

    听说k-d tree是一个骗分的好东西?(但是复杂度差评??? 还听说绍一的kdt常数特别小? KDT是什么 KDT的全称是k-degree tree,顾名思义,这是一种处理多维空间的数据结构. 例如 ...

  7. BZOJ4520:[CQOI2016]K远点对(K-D Tree)

    Description 已知平面内 N 个点的坐标,求欧氏距离下的第 K 远点对. Input 输入文件第一行为用空格隔开的两个整数 N, K.接下来 N 行,每行两个整数 X,Y,表示一个点 的坐标 ...

  8. 简单题(K-D Tree)

    简单题不简单-- 我们把单点加操作改成插入一个权值为增加量的点,将问题转化成询问一个矩阵中所有点的和,用 \(K-D\ Tree\) 维护,时间复杂度 \(O(n\sqrt{n})\) \(Code\ ...

  9. P4148 简单题 k-d tree

    思路:\(k-d\ tree\) 提交:2次 错因:整棵树重构时的严重错误:没有维护父子关系(之前写的是假重构所以没有维护父子关系) 题解: 遇到一个新的点就插进去,如果之前出现过就把权值加上. 代码 ...

随机推荐

  1. Spring源码解析-AutowiredAnnotationBeanPostProcessor

    1.实现了BeanPostProcessor接口,可先看这个接口 ApplicationContext可以在自动检测BeanPostProcessor bean,在它创建完后可以创建任何的bean. ...

  2. 通过7zip压缩备份文件bat

    for %%X in (*log20*) do "c:\Program Files\7-Zip\7z.exe" a "backups\%%X.zip" &quo ...

  3. C++中的各种“神奇”东西

    将光标放到任意的位置 void gotoxy(int x,int y)//位置函数 { COORD pos; pos.X=x; pos.Y=y; SetConsoleCursorPosition(Ge ...

  4. GitLab 密码重设

    内容全部来自: CSDN bisal GitLab 密码重设方法 假设注册邮箱为: abc@test.com 步骤 1) 登录 git 服务器 2) 执行: gitlab-rails console ...

  5. Linux rar乱码

    大家都知道,Linux下的中文乱码是一个很烦的事情,在这里我叫大家如何解决这个问题. rar乱码 ubunut下打开rar包,如果里面有中文就会显示乱码,其实就觉这个问题最简单了,只要把进入新立得,搜 ...

  6. 上传代码到github上

    初始化 git init 添加远程仓库 git remote add origin[仓库名] 仓库地址 添加文件 git add . 本地提交 git commit -m 'message' 拉去远程 ...

  7. MYSQL学习心得 优化

    这一篇主要介绍MYSQL的优化,优化MYSQL数据库是DBA和开发人员的必备技能 MYSQL优化一方面是找出系统瓶颈,提高MYSQL数据库整体性能:另一方面需要合理的结构设计和参数调整,以提高 用户操 ...

  8. Google的C++开源代码项目

    Google的C++开源代码项目 http://www.open-open.com/lib/view/open1413873531356.html v8  -  V8 JavaScript Engin ...

  9. 【 Linux 】三大主流软件负载均衡器对比(LVS、Nginx、HAproxy)

    三大主流软件负载均衡器对比(LVS.Nginx.HAproxy) (资料来自网络,做了部分的补充说明) LVS:    1. 抗负载能力强,性能高,能达到F5的60%,对内存和CPU资源消耗比较低   ...

  10. 【SQL】宿主语言接口

    一般情况下,SQL语句是嵌套在宿主语言(如C语言)中的.有两种嵌套方式: 1.调用层接口(CLI):提供一些库,库中的函数和方法实现SQL的调用 2.直接嵌套SQL:在代码中嵌套SQL语句,提交给预处 ...