2018icpcShenYangE

题解:  首先把曼哈顿距离转化为切比雪夫距离  然后维护最大值 非最大值的颜色的最大值 非最大值颜色的最小值 非最小值颜色的最小值 然后分别维护x y坐标下的值即可(细节比较多 

#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <vector>
#include <stack>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define link(x) for(edge *j=h[x];j;j=j->next)
#define inc(i,l,r) for(int i=l;i<=r;i++)
#define dec(i,r,l) for(int i=r;i>=l;i--)
const int MAXN=1e5+10;
const double eps=1e-8;
#define ll long long
const ll inf=1e18;
using namespace std;
struct edge{int t,v;edge*next;}e[MAXN<<1],*h[MAXN],*o=e;
void add(int x,int y,int vul){o->t=y;o->v=vul;o->next=h[x];h[x]=o++;}
ll read(){
    ll x=0,f=1;char ch=getchar();
    while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
    while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
    return x*f;
}
typedef struct node{
    ll maxx[2],minn[2],cmaxx[2],cminn[2];
    int Cmaxx[2],Cminn[2],Ccmaxx[2],Ccminn[2];
}node;
node d[MAXN<<2];
node up(node x,node y){
    node ans;
    for(int j=0;j<2;j++)ans.maxx[j]=ans.cmaxx[j]=-inf,ans.minn[j]=ans.cminn[j]=inf,ans.Cmaxx[j]=ans.Ccmaxx[j]=ans.Cminn[j]=ans.Ccminn[j]=0;
    for(int i=0;i<2;i++){
        if(x.maxx[i]>=y.maxx[i])ans.maxx[i]=x.maxx[i],ans.Cmaxx[i]=x.Cmaxx[i];
        else ans.maxx[i]=y.maxx[i],ans.Cmaxx[i]=y.Cmaxx[i];
        if(x.Cmaxx[i]!=y.Cmaxx[i]){
            if(x.maxx[i]<y.maxx[i])ans.cmaxx[i]=x.maxx[i],ans.Ccmaxx[i]=x.Cmaxx[i];
            else ans.cmaxx[i]=y.maxx[i],ans.Ccmaxx[i]=y.Cmaxx[i];
        }
        else ans.cmaxx[i]=-inf;
       // cout<<i<<"==="<<ans.maxx[i]<<" "<<x.Cmaxx[i]<<" "<<y.Cmaxx[i]<<" "<<ans.Ccmaxx[i]<<endl;
        if(x.Ccmaxx[i]!=ans.Cmaxx[i]){
            if(x.cmaxx[i]>=ans.cmaxx[i])ans.cmaxx[i]=x.cmaxx[i],ans.Ccmaxx[i]=x.Ccmaxx[i];
        }
        if(y.Ccmaxx[i]!=ans.Cmaxx[i]){
            if(y.cmaxx[i]>=ans.cmaxx[i])ans.cmaxx[i]=y.cmaxx[i],ans.Ccmaxx[i]=y.Ccmaxx[i];
        }
        ans.minn[i]=ans.cminn[i]=inf;
        if(x.Cmaxx[i]!=ans.Cmaxx[i]){
            if(x.maxx[i]<=ans.minn[i])ans.minn[i]=x.maxx[i],ans.Cminn[i]=x.Cmaxx[i];
        }
        if(y.Cmaxx[i]!=ans.Cmaxx[i]){
            if(y.maxx[i]<=ans.minn[i])ans.minn[i]=y.maxx[i],ans.Cminn[i]=y.Cmaxx[i];
        }
        if(x.Ccmaxx[i]!=ans.Cmaxx[i]){
            if(x.cmaxx[i]!=-inf&&x.cmaxx[i]<=ans.minn[i])ans.minn[i]=x.cmaxx[i],ans.Cminn[i]=x.Ccmaxx[i];
        }
        if(y.Ccmaxx[i]!=ans.Cmaxx[i]){
            if(y.cmaxx[i]!=-inf&&y.cmaxx[i]<=ans.minn[i])ans.minn[i]=y.cmaxx[i],ans.Cminn[i]=y.Ccmaxx[i];
        }        
        if(x.Cminn[i]!=ans.Cmaxx[i]){
            if(x.minn[i]<=ans.minn[i])ans.minn[i]=x.minn[i],ans.Cminn[i]=x.Cminn[i];
        }
        if(y.Cminn[i]!=ans.Cmaxx[i]){
            if(y.minn[i]<=ans.minn[i])ans.minn[i]=y.minn[i],ans.Cminn[i]=y.Cminn[i];
        }
        if(x.Ccminn[i]!=ans.Cmaxx[i]){
            if(x.cminn[i]<=ans.minn[i])ans.minn[i]=x.cminn[i],ans.Cminn[i]=x.Ccminn[i];
        }
        if(y.Ccminn[i]!=ans.Cmaxx[i]){
            if(y.cminn[i]<=ans.minn[i])ans.minn[i]=y.cminn[i],ans.Cminn[i]=y.Ccminn[i];
        }
        //===
        if(x.Cmaxx[i]!=ans.Cminn[i]){
            if(x.maxx[i]<=ans.cminn[i])ans.cminn[i]=x.maxx[i],ans.Ccminn[i]=x.Cmaxx[i];
        }
        if(y.Cmaxx[i]!=ans.Cminn[i]){
            if(y.maxx[i]<=ans.cminn[i])ans.cminn[i]=y.maxx[i],ans.Ccminn[i]=y.Cmaxx[i];
        }
        if(x.Ccmaxx[i]!=ans.Cminn[i]){
            if(x.cmaxx[i]!=-inf&&x.cmaxx[i]<=ans.cminn[i])ans.cminn[i]=x.cmaxx[i],ans.Ccminn[i]=x.Ccmaxx[i];
        }
        if(y.Ccmaxx[i]!=ans.Cminn[i]){
            if(y.cmaxx[i]!=-inf&&y.cmaxx[i]<=ans.cminn[i])ans.cminn[i]=y.cmaxx[i],ans.Ccminn[i]=y.Ccmaxx[i];
        } 
        //====
        if(x.Cminn[i]!=ans.Cminn[i]){
            if(x.minn[i]<=ans.cminn[i])ans.cminn[i]=x.minn[i],ans.Ccminn[i]=x.Cminn[i];
        }
        if(y.Cminn[i]!=ans.Cminn[i]){
            if(y.minn[i]<=ans.cminn[i])ans.cminn[i]=y.minn[i],ans.Ccminn[i]=y.Cminn[i];
        }
        if(x.Ccminn[i]!=ans.Cminn[i]){
            if(x.cminn[i]<=ans.cminn[i])ans.cminn[i]=x.cminn[i],ans.Ccminn[i]=x.Ccminn[i];
        }
        if(y.Ccminn[i]!=ans.Cminn[i]){
            if(y.cminn[i]<=ans.cminn[i])ans.cminn[i]=y.cminn[i],ans.Ccminn[i]=y.Ccminn[i];
        }       
    }
    return ans;
}
typedef struct Q{
    ll x,y;int c;
}Q;
Q que[MAXN];
void built(int rt,int l,int r){
     for(int i=0;i<2;i++){
        d[rt].maxx[i]=d[rt].cmaxx[i]=-inf;
        d[rt].minn[i]=d[rt].cminn[i]=inf;
        d[rt].Cmaxx[i]=d[rt].Ccmaxx[i]=d[rt].Cminn[i]=d[rt].Ccminn[i]=0;
    }
    if(l==r){
        d[rt].maxx[0]=que[l].x;d[rt].maxx[1]=que[l].y;d[rt].Cmaxx[0]=d[rt].Cmaxx[1]=que[l].c;
        d[rt].cmaxx[0]=d[rt].cmaxx[1]=-inf;
        d[rt].minn[0]=d[rt].minn[1]=inf;
        d[rt].cminn[0]=que[l].x;d[rt].cminn[1]=que[l].y;d[rt].Ccminn[0]=d[rt].Ccminn[1]=que[l].c;
        return ;
    }
    int mid=(l+r)>>1;
    built(rt<<1,l,mid);
    built(rt<<1|1,mid+1,r);
    d[rt]=up(d[rt<<1],d[rt<<1|1]);
    // cout<<l<<"===="<<r<<endl;
    // cout<<"x: "<<endl;
    // cout<<d[rt].maxx[0]<<" "<<d[rt].cmaxx[0]<<" "<<d[rt].minn[0]<<" "<<d[rt].cminn[0]<<endl;
    // cout<<"y: "<<endl;
    // cout<<d[rt].maxx[1]<<" "<<d[rt].cmaxx[1]<<" "<<d[rt].minn[1]<<" "<<d[rt].cminn[1]<<endl;
    // cout<<d[rt].Cmaxx[1]<<" "<<d[rt].Ccmaxx[1]<<" "<<d[rt].Cminn[1]<<" "<<d[rt].Ccminn[1]<<endl;
}
void update1(int rt,int l,int r,int t,ll x,ll y){
    if(l==r){
        d[rt].maxx[0]=d[rt].cminn[0]=x;
        d[rt].maxx[1]=d[rt].cminn[1]=y;
        return ;
    }
    int mid=(l+r)>>1;
    if(t<=mid)update1(rt<<1,l,mid,t,x,y);
    else update1(rt<<1|1,mid+1,r,t,x,y);
    d[rt]=up(d[rt<<1],d[rt<<1|1]);
}
void update2(int rt,int l,int r,int t,int c){
    if(l==r){
        d[rt].Cmaxx[0]=d[rt].Cmaxx[1]=c;
        d[rt].Ccminn[0]=d[rt].Ccminn[1]=c;
        return ;
    }
    int mid=(l+r)>>1;
    if(t<=mid)update2(rt<<1,l,mid,t,c);
    else update2(rt<<1|1,mid+1,r,t,c);
    d[rt]=up(d[rt<<1],d[rt<<1|1]);
}
node ans;bool flag;
void querty(int rt,int l,int r,int ql,int qr){
    if(ql<=l&&r<=qr){
        //cout<<l<<"==="<<r<<" "<<flag<<endl;
        if(!flag)ans=d[rt],flag=1;
        else ans=up(ans,d[rt]);
                //         cout<<"x: "<<endl;
                // cout<<ans.maxx[0]<<" "<<ans.cmaxx[0]<<" "<<ans.minn[0]<<" "<<ans.cminn[0]<<endl;
                // cout<<ans.Cmaxx[0]<<" "<<ans.Ccmaxx[0]<<" "<<ans.Cminn[0]<<" "<<ans.Ccminn[0]<<endl;
                // cout<<"y: "<<endl;
                // cout<<ans.maxx[1]<<" "<<ans.cmaxx[1]<<" "<<ans.minn[1]<<" "<<ans.cminn[1]<<endl;
        return ;
    }
    int mid=(l+r)>>1;
    if(ql<=mid)querty(rt<<1,l,mid,ql,qr);
    if(qr>mid)querty(rt<<1|1,mid+1,r,ql,qr);
}
int main(){
    int _=read();int ca=0;
    while(_--){
        int n=read();int m=read();
        int c,k,op,l,r;
        ll x,y;
        inc(i,1,n)x=read(),y=read(),c=read(),que[i].x=x+y,que[i].y=y-x,que[i].c=c;
        built(1,1,n);
       printf("Case #%d:\n",++ca);
        while(m--){
            op=read();
            if(op==1)k=read(),x=read(),y=read(),update1(1,1,n,k,que[k].x+x+y,que[k].y+y-x),que[k].x+=(x+y),que[k].y+=(y-x);
            else if(op==2)k=read(),c=read(),update2(1,1,n,k,c);
            else {
                l=read();r=read();
                for(int j=0;j<2;j++)ans.maxx[j]=ans.cmaxx[j]=-inf,ans.minn[j]=ans.cminn[j]=inf,ans.Cmaxx[j]=ans.Ccmaxx[j]=ans.Cminn[j]=ans.Ccminn[j]=0;
                flag=0;
                querty(1,1,n,l,r);
                // cout<<"x: "<<endl;
                // cout<<ans.maxx[0]<<" "<<ans.cmaxx[0]<<" "<<ans.minn[0]<<" "<<ans.cminn[0]<<endl;
                // cout<<"y: "<<endl;
                // cout<<ans.maxx[1]<<" "<<ans.cmaxx[1]<<" "<<ans.minn[1]<<" "<<ans.cminn[1]<<endl;
                if(ans.cmaxx[0]==-inf)printf("0\n");
                else{
                    ll ans1=max(1ll*ans.maxx[0]-ans.minn[0],1ll*ans.cmaxx[0]-ans.cminn[0]);
                    ll ans2=max(1ll*ans.maxx[1]-ans.minn[1],1ll*ans.cmaxx[1]-ans.cminn[1]);
                    printf("%lld\n",max(ans1,ans2));
                }
            }
        }
    }
    return 0;
}

  

E. The Kouga Ninja Scrolls
time limit per test
6 seconds
memory limit per test
1024 megabytes
input
standard input
output
standard output

The story centres around nn rival ninja clans labelled from 11 to nn, and nn ninjas also labelled from 11 to nn. For each ninja, the family decides his/her initial belief and affiliation of a clan. But some conflicts occur in the story, such as two young souls, facing the rivalry between their ninjas but falling in love, can change their mind and some ninjas may desert to other opposite clans.

These ninjas are living in a pretty quiet town with straightforward footpaths, but they live like a group of wild animals eyeing up ninjas of other clans, continually escaping and looking forward to killing. The governor of this region knows that the end of the war between them depends on those ninjas belonging to different clans who have the farthest distance.

That is what a noble vulture as the honest servant of the governor should do. Now you need to act as a vulture, and report in real time to the governor the largest distance between two ninjas that belong to different clans and whose labels are in a specified consecutive range. As a practical matter, the distance between two points in the plane is defined as the Manhattan distance, which is equal to the sum of the absolute differences of their Cartesian coordinates.

Input

The input contains several test cases, and the first line contains a positive integer TT indicating the number of test cases which is up to 6060.

For each test case, the first line contains two integers nn, indicating the number of clans and also the number of ninjas, and mm, indicating the total number of special conflicts and inquiries from the governor, where 1n1051≤n≤105 and 1m1051≤m≤105.

The following nn lines describe the initial situations of all ninjas. The ii-th line of them contains three integers x,yx,y and cc indicating the initial position where the ii-th ninja stays is (x,y)(x,y) and the initial clan which he/she belongs to is the cc-th one, where 109x,y109−109≤x,y≤109 and 1cn1≤c≤n.

Then the following mm lines describe all special conflicts that change someone's position or his/her clan, and all inquiries from the governor in chronological order. Each of them must be in one of the following forms.

  • 1 k x y, the kk-th ninja changes his/her position along the direction (x,y)(x,y); that is to say, he/she moves to the new position (x0+x,y0+y)(x0+x,y0+y) where (x0,y0)(x0,y0) is his/her original position.
  • 2 k c, the kk-th ninja changes his/her mind and decides to work for the cc-th clan.
  • 3 l r, the governor asks his vulture for ninjas labelled from ll to rr (inclusive) the largest distance between two of them belonging to different clans.

All k,x,y,l,rk,x,y,l,r and cc mentioned in these mm lines satisfy 1k,cn1≤k,c≤n, 109x,y109−109≤x,y≤109 and 1lrn1≤l≤r≤n.

We guarantee that the sum of nn in all test cases is no larger than 5×1055×105, and the sum of mm in all test cases is no larger than 5×1055×105 as well.

Output

For each test case, output a line containing "Case #x:" (without quotes) at first, where x is the test case number starting from 11.

Then for each inquire, output an integer in a line indicating the answer. If all of the related ninjas belong to the same clan, output 00 instead.

posted @ 2018-11-12 13:21  wang9897  阅读(188)  评论(0编辑  收藏  举报