感人肺腑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的更多相关文章

  1. 【kd-tree】bzoj2716 [Violet 3]天使玩偶

    #include<cstdio> #include<cmath> #include<algorithm> using namespace std; #define ...

  2. BZOJ2716 [Violet]天使玩偶(cdq分治+树状数组)

    非常裸的KD-tree.然而我没学啊. 考虑如何离线求一个点在平面中的曼哈顿最近点. 绝对值显得有点麻烦,于是把绝对值拆开分情况讨论一波.对于横坐标小于该点的,记录对于纵坐标的前缀x+y最大值和后缀x ...

  3. [BZOJ2716]天使玩偶

    [BZOJ2716]天使玩偶 题目大意: 一个平面直角坐标系,坐标\(1\le x,y\le10^6\).\(n(n\le10^6)\)次操作,操作包含以下两种: 新增一个点\((x,y)\): 询问 ...

  4. [BZOJ2716] [Violet 3]天使玩偶(CDQ分治)

    [BZOJ2716] [Violet 3]天使玩偶(CDQ分治) 题面 Ayu 在七年前曾经收到过一个天使玩偶,当时她把它当作时间囊埋在了地下.而七年后 的今天,Ayu 却忘了她把天使玩偶埋在了哪里, ...

  5. bzoj2648SJY摆棋子&&bzoj2716[Violet 3]天使玩偶*

    bzoj2648SJY摆棋子 bzoj2716[Violet 3]天使玩偶 题意: 棋盘上有n个棋子,现在有m个操作,一种是加棋子,一种是查询离某个点最近的棋子.n,m≤500000. 题解: 先将已 ...

  6. bzoj2716: [Violet 3]天使玩偶

    #include <iostream> #include <cstdio> #include <cstring> #include <cmath> #i ...

  7. bzoj2716/2648 / P4169 [Violet]天使玩偶/SJY摆棋子

    P4169 [Violet]天使玩偶/SJY摆棋子 k-d tree 模板 找了好几天才发现输出优化错了....真是zz...... 当子树非常不平衡时,就用替罪羊树的思想,拍扁重建. luogu有个 ...

  8. BZOJ2716 KD-Tree

    好久没写博客了 回去赶了好久文化课 颓欲见长 突然翻到fc爷的KD-Tree板子 来切了到裸题 对于一开始的数据我们可以先预处理 具体的排序方式见板子 其实就是我们对每次选定的一块选一个维度来排序啦 ...

  9. 【BZOJ2716】天使玩偶【kd树】

    这个题要求kd树支持两个操作. 1.插入一个新的点. 2.查询某个点最近曼哈顿距离. 注意查询曼哈顿距离和查询欧几里得距离,是有区别的.(估价函数不同). #include <cstdio> ...

随机推荐

  1. C# ACM poj1005

    大水题呀 public static void acm1005(int n, float[,] a) { float pi = 3.1415926f, rr; int years; ; i < ...

  2. 霍纳法则(Horner's rule)

    卡在hdu 1402 的高精度乘法了,要用FFT(快速傅里叶变换),然后看到了这个霍纳法则,顺便就写下来了. 霍纳法则:求多项式值的一个快速算法. 简单介绍: 假设有n+2个数 , a0,a1,a2, ...

  3. Linux启动级别

    一共有7种启动级别,分别为: #   0 - halt (Do NOT set initdefault to this)  #   1 - Single user mode  #   2 - Mult ...

  4. iOS网络编程总结

    好长时间没有进行更行了,最近学到AFNetworking框架,在学习完成之后做出一个总结 1.第三方网络的框架 AFNEtworking使用简单,对最新的iOS特性都有很好的支持,对NSURL进行了封 ...

  5. 关于不使用web服务实现文本框自动完成扩展

    来博客园很久了,一直是伸手党,呵呵,现在终于申请了一个账号并开通了博客 下面分享下之前在一个项目里遇到的问题 前段时间在一个项目里要求在文本框内输入要搜索的内容,自动提示与此内容相关的词条 当时在博客 ...

  6. Magento Api 记录

    magento api 首次接触 (-) /** * magento Api 身份验证 调用示例 * Example of simple product POST using Admin accoun ...

  7. HttpContext

    HttpContext 类:封装有关个别 HTTP 请求的所有 HTTP 特定的信息.也有人叫上下文信息. 1.生存周期:从客户端用户点击并产生了一个向服务器发送请求开始---服务器处理完请求并生成返 ...

  8. 在Ubuntu Linux下怎样安装QQ

    最近好多人在吐槽Linux下上QQ简直就是煎熬,网页版的不方便,网上各种版本的QQ要么是功能不全.要么是界面丑到爆,要么是运行不稳定.那么这次为大家带来一个功能完整.运行稳定的wineQQ安装过程. ...

  9. CATextLayer

    CATextLayer *layer = [[CATextLayer alloc] init]; layer.frame  = CGRectMake(0, 300, 100, 100); 字体模糊 l ...

  10. WiFi与WLAN的区别

    很多人到了某一个地方首选要找的就是无线网络,有时候还会问周围的人:这里有WiFi吗?或者说:这里有WLAN吗?那WiFi和WLAN有什么区别呢? 简单来讲,WiFi是无线保真(wireless fid ...