mdzz数据范围看错了
#include
#include
#include
#include
#include
using namespace std;
typedef long long LL;
inline int read()
{
int x=0;bool f=0;char c=getchar();
for (;c<'0'||c>'9';c=getchar()) f=c=='-'?1:0;
for (;c>='0'&&c<='9';c=getchar()) x=x*10+c-'0';
return f?-x:x;
}
const int N=500010,M=1000010,oo=0x3f3f3f3f;
int n,m,q=0,maxl=0,ans[N],ss[M];
struct na
{
int x,y,id,t;
}e[N<<1],e1[N<<1],e2[N<<1];
inline bool cmp(const na &a,const na &b)
{
if (a.y!=b.y) return a.y=r||hd>=tl) return;
int mid=l+r>>1;
for (int i=hd;i<=tl;i++)
{
if (e[i].t<=mid&&!e[i].id) update1(e[i].x,-e[i].x-e[i].y);
if (e[i].t>mid&&e[i].id) ans[e[i].id]=min(ans[e[i].id],e[i].x+e[i].y+query1(e[i].x));
}
for (int i=hd;i<=tl;i++)
if (e[i].t<=mid&&!e[i].id) recover1(e[i].x);
for (int i=hd;i<=tl;i++)
{
if (e[i].t<=mid&&!e[i].id) update2(e[i].x,e[i].x-e[i].y);
if (e[i].t>mid&&e[i].id) ans[e[i].id]=min(ans[e[i].id],-e[i].x+e[i].y+query2(e[i].x));
}
for (int i=hd;i<=tl;i++)
if (e[i].t<=mid&&!e[i].id) recover2(e[i].x);
for (int i=tl;i>=hd;i--)
{
if (e[i].t<=mid&&!e[i].id) update1(e[i].x,-e[i].x+e[i].y);
if (e[i].t>mid&&e[i].id) ans[e[i].id]=min(ans[e[i].id],e[i].x-e[i].y+query1(e[i].x));
}
for (int i=tl;i>=hd;i--)
if (e[i].t<=mid&&!e[i].id) recover1(e[i].x);
for (int i=tl;i>=hd;i--)
{
if (e[i].t<=mid&&!e[i].id) update2(e[i].x,e[i].x+e[i].y);
if (e[i].t>mid&&e[i].id) ans[e[i].id]=min(ans[e[i].id],-e[i].x-e[i].y+query2(e[i].x));
}
for (int i=tl;i>=hd;i--)
if (e[i].t<=mid&&!e[i].id) recover2(e[i].x);
int l1=0,l2=0,lp=hd;
for (int i=hd;i<=tl;i++)
if (e[i].t<=mid) e1[++l1]=e[i];
else e2[++l2]=e[i];
for (int i=1;i<=l1;i++) e[lp++]=e1[i];
for (int i=1;i<=l2;i++) e[lp++]=e2[i];
solve(hd,hd+l1-1,l,mid);
solve(hd+l1,tl,mid+1,r);
}
int main()
{
memset(ss,0x3f,sizeof ss);
n=read();m=read();
for (int i=1;i<=n;i++) maxl=max(maxl,e[i].x=read()+1),e[i].y=read()+1,e[i].t=i;
for (int i=n+1;i<=n+m;i++)
{
if (read()==2) e[i].id=++q,ans[q]=oo;
maxl=max(maxl,e[i].x=read()+1),e[i].y=read()+1,e[i].t=i;
}
sort(e+1,e+n+m+1,cmp);
solve(1,n+m,1,n+m);
for (int i=1;i<=q;i++) printf("%d\n",ans[i]);
return 0;
}