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> ...
随机推荐
- 02线性表链式存储_LinkList--(线性表)
#include "stdio.h" #include "string.h" #include "ctype.h" #include &qu ...
- ios - cordova(phoneGap)
安装教程 下载 node.js. http://nodejs.org/ 下载后,直接安装就可以了. 安装 Cordova工具, $ sudo npm install -g cordova 创建APP: ...
- 2D游戏模型中动态分层的处理 及解决方案 (适用于 webgame 手游等资源控制较严格类型)
文章若非特别注明转载,皆是原创,转载请注明出处. 本文地址:http://www.cnblogs.com/bobolive/p/3537215.html 2D游戏中模型一般都有换装逻辑,特别是联网游戏 ...
- JavaScript 对象的几种创建方法
/** * Created by 2016 on 2016/6/4. */ function Box(){ var obj = new obj(); obj.name = "Lee" ...
- 支持阻塞操作和轮询操作的globalfifo设备驱动代码分析以及测试代码
#include <linux/module.h> #include <linux/types.h> #include <linux/fs.h> #include ...
- Python Socket,How to Create Socket Cilent? - 网络编程实例
文章出自:Python socket – network programming tutorial by Silver Moon 原创译文,如有版权问题请联系删除. Network programin ...
- 角色控制器 Character Controller
Unity中,1个单位尺寸代表1米.即在Unity中创建一个Cube的尺寸是1x1x1米大小. Unity推荐把人的身高定为大约2个Unity单位高度(2米). 为了截取角色的全身照,需要把角色Ins ...
- 微软职位内部推荐-ATG Engineer II
微软近期Open的职位: ATG Engineer - GeneralistReady to work on some of the most advanced hardware on the pla ...
- sencha touch mvc
controller: Ext.define('MyApp2.controller.MyController1', { extend: 'Ext.app.Controller', config: { ...
- Python属性、方法和类管理系列之----元类
元类的介绍 请看位于下面网址的一篇文章,写的相当好. http://blog.jobbole.com/21351/ 实例补充 class Meta(type): def __new__(meta, c ...