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> ...
随机推荐
- Cannot connect to (local) sql server 2008
Make following steps to solve the issue: Cannot connect to (local). ADDITIONAL INFORMATION: Login fa ...
- Mac或Linux中对Android抓包
转载说明 本篇文章可能已经更新,最新文章请转:http://www.sollyu.com/mac-or-linux-android-caught/ 说明 首先要到http://www.charlesp ...
- 创建线程的两种方式比较Thread VS Runnable
1.首先来说说创建线程的两种方式 一种方式是继承Thread类,并重写run()方法 public class MyThread extends Thread{ @Override public vo ...
- Keil 4 与Proteus 7.8联调
实验环境: windows 8.1 pro with Keil 4 and Proteus 7.8 both cracked. 步骤: 下载联调工具Vdmagdi,安装. keil下Option/De ...
- winform 通过 html 与swf 交互 简单案例
在上一篇 winform 与 html 交互 简单案例 中讲了winform与html之间的简单交互,接下来的内容是在winform中以html为中转站,实现将swf嵌入winform中并实现交互. ...
- mysql触发器的例子--插入前更新数据
本文介绍下,一个mysql触发器的例子,在数据插入前更新相关内容,有需要的朋友参考下. mysql触发器的例子,如下: view source print? 001 mysql> CREATE ...
- 大型B/S系统技术总结(不断更新)
看了<淘宝技术这十年>和<大型网站系统与Java中间件实践>这些书,对大型B/S系统的构建越来越感兴趣,于是尝试收集和总结一些常用的技术手段.不过大型网站的架构是根据业务需求不 ...
- #Leet Code# Gray Code
描述: 要求相邻数2进制差一位 先获得n-1的列表表示小于 2^(n-1) 的符合要求的列表,加上最高位的加成 2^(n-1) 就是大于等于 2^(n-1) 的符合要求的列表,后者翻转一下就能够与前者 ...
- poj 1830 开关问题
开关问题 题意:给n(0 < n < 29)开关的初始和最终状态(01表示),以及开关之间的关联关系(关联关系是单向的输入a b表示a->b),问有几种方式得到最终的状态.否则输出字 ...
- 上传图片+浏览+裁切 Demo(无后台处理部分)
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...