bzoj2716
感人肺腑pascal过不去系列(可能是自己弱,因为有pascal过去了毕竟)
那个这种平面点还有一种处理方法是kd tree,太弱了不会有时间学一下
我还是用了cdq分治,首先肯定要把绝对值这个不和谐的东西去掉
然后就变成了4个部分,这样就非常好维护了,然后还是cdq分治的一般步骤
有优化建议的欢迎指教……
const inf=;
type node=record
x,y,p,z:longint;
end; var b,a:array[..] of node;
g,q,c,next,last:array[..] of longint;
v:array[..] of boolean;
ans:array[..] of longint;
mx,t,i,j,my,n,m,tot,p:longint; function max(a,b:longint):longint;
begin
if a>b then exit(a) else exit(b);
end; function min(a,b:longint):longint;
begin
if a>b then exit(b) else exit(a);
end; function lowbit(x:longint):longint;
begin
exit(x and (-x));
end; procedure add(x,w:longint);
begin
while x<=p do
begin
if not v[x] then
begin
inc(tot);
q[tot]:=x;
v[x]:=true;
end;
c[x]:=max(c[x],w);
x:=x+lowbit(x);
end;
end; function ask(x:longint):longint;
begin
ask:=-inf;
while x> do
begin
ask:=max(ask,c[x]);
x:=x-lowbit(x);
end;
end; procedure work(s,t,dx,dy:longint);
var i,k,y:longint;
begin
tot:=;
i:=s;
while i<>t do
begin
k:=dx*b[i].x+dy*b[i].y;
if dy=- then y:=g[my-b[i].y+] else y:=g[b[i].y];
if b[i].z= then
add(y,k)
else ans[b[i].p-n]:=min(ans[b[i].p-n],abs(k-ask(y)));
i:=i+dx;
end;
for i:= to tot do
begin
c[q[i]]:=-inf;
v[q[i]]:=false;
end;
end; procedure cdq(l,r:longint);
var m,l1,l2,t,i,tt:longint;
begin
if l=r then exit;
m:=(l+r) shr ;
l2:=; t:=;
for i:=l to r do
if (a[i].z=) and (a[i].p<=m) then
begin
inc(t);
b[t]:=a[i];
end
else if (a[i].z=) and (a[i].p>m) then
begin
inc(t);
b[t]:=a[i];
inc(l2);
end; if l2> then
begin
work(,t+,,);
work(t,,-,);
work(,t+,,-);
work(t,,-,-);
end;
t:=l2; tt:=;
l1:=l; l2:=m+;
for i:=l to r do
if a[i].p<=m then
begin
b[l1]:=a[i];
inc(l1);
if a[i].z= then inc(tt);
end
else begin
b[l2]:=a[i];
inc(l2);
end; for i:=l to r do
a[i]:=b[i];
if tt> then cdq(l,m);
if t> then cdq(m+,r);
end; begin
readln(n,m);
for i:= to n do
begin
readln(b[i].x,b[i].y);
inc(b[i].x);
inc(b[i].y);
b[i].p:=i;
b[i].z:=;
my:=max(my,b[i].y);
end;
for i:=n+ to n+m do
begin
readln(b[i].z,b[i].x,b[i].y);
inc(b[i].x);
inc(b[i].y);
b[i].p:=i;
my:=max(my,b[i].y);
end;
for i:= to n+m do
begin
next[i]:=last[b[i].x];
last[b[i].x]:=i;
mx:=max(mx,b[i].x);
v[b[i].y]:=true;
v[my-b[i].y+]:=true;
end;
p:=;
for i:= to my do
begin
c[i]:=-inf;
if v[i] then
begin
inc(p);
g[i]:=p;
v[i]:=false;
end;
end;
fillchar(ans,sizeof(ans),);
for i:= to mx do //这里只需要以x为第一关键字即可,因为计算贡献的时候会从四个方向算,总有一个会算到
begin
j:=last[i];
while j<> do
begin
inc(t);
a[t]:=b[j];
j:=next[j];
end;
end;
t:=;
for i:= to n+m do //先处理初始值对询问的影响
if (a[i].z=) or (a[i].p<=n) then
begin
inc(t);
b[t]:=a[i];
end; work(,t+,,);
work(t,,-,);
work(,t+,,-);
work(t,,-,-);
t:=n;
for i:= to n+m do
if a[i].p>n then
begin
inc(t);
b[t]:=a[i];
end; for i:=n+ to n+m do
a[i]:=b[i]; cdq(n+,n+m); //分治修改询问序列
for i:= to m do
if ans[i]<inf then writeln(ans[i]);
end.
bzoj2716的更多相关文章
- 【kd-tree】bzoj2716 [Violet 3]天使玩偶
#include<cstdio> #include<cmath> #include<algorithm> using namespace std; #define ...
- BZOJ2716 [Violet]天使玩偶(cdq分治+树状数组)
非常裸的KD-tree.然而我没学啊. 考虑如何离线求一个点在平面中的曼哈顿最近点. 绝对值显得有点麻烦,于是把绝对值拆开分情况讨论一波.对于横坐标小于该点的,记录对于纵坐标的前缀x+y最大值和后缀x ...
- [BZOJ2716]天使玩偶
[BZOJ2716]天使玩偶 题目大意: 一个平面直角坐标系,坐标\(1\le x,y\le10^6\).\(n(n\le10^6)\)次操作,操作包含以下两种: 新增一个点\((x,y)\): 询问 ...
- [BZOJ2716] [Violet 3]天使玩偶(CDQ分治)
[BZOJ2716] [Violet 3]天使玩偶(CDQ分治) 题面 Ayu 在七年前曾经收到过一个天使玩偶,当时她把它当作时间囊埋在了地下.而七年后 的今天,Ayu 却忘了她把天使玩偶埋在了哪里, ...
- bzoj2648SJY摆棋子&&bzoj2716[Violet 3]天使玩偶*
bzoj2648SJY摆棋子 bzoj2716[Violet 3]天使玩偶 题意: 棋盘上有n个棋子,现在有m个操作,一种是加棋子,一种是查询离某个点最近的棋子.n,m≤500000. 题解: 先将已 ...
- bzoj2716: [Violet 3]天使玩偶
#include <iostream> #include <cstdio> #include <cstring> #include <cmath> #i ...
- bzoj2716/2648 / P4169 [Violet]天使玩偶/SJY摆棋子
P4169 [Violet]天使玩偶/SJY摆棋子 k-d tree 模板 找了好几天才发现输出优化错了....真是zz...... 当子树非常不平衡时,就用替罪羊树的思想,拍扁重建. luogu有个 ...
- BZOJ2716 KD-Tree
好久没写博客了 回去赶了好久文化课 颓欲见长 突然翻到fc爷的KD-Tree板子 来切了到裸题 对于一开始的数据我们可以先预处理 具体的排序方式见板子 其实就是我们对每次选定的一块选一个维度来排序啦 ...
- 【BZOJ2716】天使玩偶【kd树】
这个题要求kd树支持两个操作. 1.插入一个新的点. 2.查询某个点最近曼哈顿距离. 注意查询曼哈顿距离和查询欧几里得距离,是有区别的.(估价函数不同). #include <cstdio> ...
随机推荐
- 无限大整数相加算法的C语言源代码
忙里偷闲,终于完成了无限大整数相加算法的C语言代码,无限大整数相加算法的算法分析在这里. 500位的加法运行1000次,不打印结果的情况下耗时0.036秒,打印结果的情况下耗时16.285秒. 下面是 ...
- Java多线程的安全问题
/*多线程的安全问题1.为什么会出现安全问题?因为程序在运行时,会出现一个线程在判断条件满足后,具备了执行资格,但没有运行代码后一个线程也判断了条件,也具备了执行资格,后一个线程运行了代码,但这时候, ...
- bzoj1002:[FJOI2007]轮状病毒
思路:一道很裸的生成树计数问题,然而要高精度,而且听说直接行列式求值会被卡精度,所以可以模拟行列式求值的过程得到递推公式:f[i]=3*f[i-1]-f[i-2]+2,证明详见vfk博客: http: ...
- HDU分类
原地址:http://www.byywee.com/page/M0/S607/607452.html 总结了一下ACM STEPS的各章内容,趁便附上我的Steps题号(每人的不一样). 别的,此文首 ...
- OpenJudge/Poj 1321 棋盘问题
1.链接地址: http://bailian.openjudge.cn/practice/1321 http://poj.org/problem?id=1321 2.题目: 棋盘问题 Time Lim ...
- jQuery去掉导航分割线的最后一条竖线
#top #navigation ul li { float:left; width:120px; background:url(../images/navline.jpg) no-repeat 11 ...
- 可以自动安装mysql数据库的一个shell脚本
发布:thatboy 来源:脚本学堂 [大 中 小] 分享一例shell脚本,可以实现mysql数据库的自动安装,脚本写的不错,无论是用来学习,还是生产环境中应用,都是不错的,有需要的朋友 ...
- thinkphp 框架的学习(1) 扩展配置文件
在config.php里面写入 1:'LOAD_EXT_CONFIG' => array('SETTINGS' => 'settings'); 系统会判断是否有参数:LOAD_EXT_CO ...
- 一步步学习ASP.NET MVC3 (2)——入门程序
请注明转载地址:http://www.cnblogs.com/arhat 在上一节中,我们只是简单的介绍了什么是MVC及MVC的运行原理.而本节呢,主要来实现下一ASP.NET MVC3的开发流程,并 ...
- JavaScript中的Function类型浅析
1. Function类型是js中引用类型之一,每个函数实际上都是Function类型的实例对象,具有自己的属性和方法.正因为函数式对象,所以函数名实际上也是一个指向函数对象的指针. 2. 常用的函数 ...