感人肺腑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.