Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|---|
98289 | CSYZ_using | 早凉爱旅行2 | C++ | 通过 | 100 | 208 MS | 26820 KB | 3186 | 2023-08-14 14:20:23 |
#include<bits/stdc++.h> #define ll long long using namespace std; int read(){ int x;char c; while((c=getchar())<'0'||c>'9'); x=c-48; while((c=getchar())>='0'&&c<='9')x=x*10-48+c; return x; } void write(int x){ if(x>9)write(x/10); putchar(x%10+48); } struct A{ ll a,b; A(){a=b=0;} A(ll _a,ll _b){a=_a;b=_b;} }; struct B{ ll aa,ab,ba,bb; B(){aa=ab=ba=bb=0;} B(ll _aa,ll _ab,ll _ba,ll _bb){aa=_aa;ab=_ab;ba=_ba;bb=_bb;} }; A AB(A x,B y){return A(min(x.a+y.aa,x.b+y.ba),min(x.a+y.ab,x.b+y.bb));} B BB(B x,B y){return B(min(x.aa+y.aa,x.ab+y.ba),min(x.aa+y.ab,x.ab+y.bb),min(x.ba+y.aa,x.bb+y.ba),min(x.ba+y.ab,x.bb+y.bb));} const int maxn=200020; int x[maxn],y[maxn]; B num[maxn<<2]; B workget(int id,int x,int y,int tx,int ty){return B(abs(x-tx)+1,id+id+1+1-x-ty+1,id+id+1+1-y-tx+1,abs(y-ty)+1);} void init(int p,int l,int r){ if(l==r){num[p]=workget(l,x[l],y[l],x[l+1],y[l+1]);return;} int mid=(l+r)/2; init(2*p,l,mid);init(2*p+1,mid+1,r); num[p]=BB(num[2*p],num[2*p+1]); } void change(int p,int l,int r,int t){ if(l==r){num[p]=workget(l,x[l],y[l],x[l+1],y[l+1]);return;} int mid=(l+r)/2; if(t<=mid)change(2*p,l,mid,t); else change(2*p+1,mid+1,r,t); num[p]=BB(num[2*p],num[2*p+1]); } void check(int p,int l,int r,int L,int R,A &t){ if(L<=l&&r<=R){t=AB(t,num[p]);return;} int mid=(l+r)/2; if(L<=mid)check(2*p,l,mid,L,R,t); if(mid<R)check(2*p+1,mid+1,r,L,R,t); } int main(){ int n=read(),m=n-2,q=read(),op,ta,tb,tc,td,va,vb; for(int i=1;i<n;i++) x[i]=read(),y[i]=read(); init(1,1,m); A tmp;ll ans,kr; while(q--){ op=read(); if(op==1){ ta=read();tb=read();tc=read(); x[ta]=tb;y[ta]=tc; if(ta!=1)change(1,1,m,ta-1); if(ta!=n-1)change(1,1,m,ta); } else{ ta=read();tb=read();tc=read();td=read(); if((va=max(ta,tb))>(vb=max(tc,td)))swap(ta,tc),swap(tb,td),swap(va,vb); if(va==vb){ if(ta==va&&tc==vb)printf("%d\n",abs(td-tb)); else if(tb==va&&td==vb)printf("%d\n",abs(ta-tc)); else printf("%d\n",abs(va+vb-min(ta,tb)-min(tc,td))); } else if(va+1==vb){ kr=ans=1; if(ta==va)kr+=abs(tb-x[va]),ans+=va+va-y[va]-tb; else kr+=va+va-x[va]-ta,ans+=abs(ta-y[va]); if(tc==vb)kr+=abs(td-x[va]),ans+=vb+vb-y[va]-td; else kr+=vb+vb-x[va]-tc,ans+=abs(tc-y[va]); printf("%lld\n",min(kr,ans)); } else{ tmp.a=tmp.b=0; if(ta==va)tmp.a+=abs(tb-x[va]),tmp.b+=va+va-y[va]-tb; else tmp.a+=va+va-x[va]-ta,tmp.b+=abs(ta-y[va]); check(1,1,m,va,vb-2,tmp); tmp.a++;tmp.b++; if(tc==vb)tmp.a+=abs(x[vb-1]-td),tmp.b+=vb+vb-td-y[vb-1]; else tmp.a+=vb+vb-tc-x[vb-1],tmp.b+=abs(y[vb-1]-tc); printf("%lld\n",min(tmp.a,tmp.b)); } } } return 0; }