QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#598036#4421. Taxiship2077#AC ✓250ms31348kbC++231.5kb2024-09-28 20:10:592024-09-28 20:10:59

Judging History

你现在查看的是最新测评结果

  • [2024-09-28 20:10:59]
  • 评测
  • 测评结果:AC
  • 用时:250ms
  • 内存:31348kb
  • [2024-09-28 20:10:59]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
constexpr int M=1e5+5;int n,q,ans[M];
vector<tuple<int,int,int>>upd,qry;
void solve(vector<tuple<int,int,int>>&upd,vector<tuple<int,int,int>>&qry,int ql,int qr){
    if (upd.empty()||qry.empty()||ql>qr) return;
    int mid=ql+qr>>1;
    vector<tuple<int,int,int>>updl,updr,qryl,qryr;
    int res[4]={-INT_MAX,-INT_MAX,-INT_MAX,-INT_MAX};
    for (auto [w,x,y]:upd){
        if (w>=mid){
            res[0]=max(res[0],x+y);
            res[1]=max(res[1],x-y);
            res[2]=max(res[2],y-x);
            res[3]=max(res[3],-x-y);
        }
        if (w<=mid) updl.emplace_back(w,x,y);
        else updr.emplace_back(w,x,y);
    }
    for (auto [x,y,id]:qry){
        if (res[0]==-INT_MAX) {qryl.emplace_back(x,y,id);continue;} 
        int tmp=max({-x-y+res[0],y-x+res[1],x-y+res[2],x+y+res[3]});
        ans[id]=max(ans[id],min(tmp,mid));
        if (tmp<=mid) qryl.emplace_back(x,y,id);
        else qryr.emplace_back(x,y,id);
    }
    solve(updl,qryl,ql,mid-1);
    solve(updr,qryr,mid+1,qr);
}
void solve(){
    cin>>n>>q;upd.clear();qry.clear();
    for (int i=1;i<=n;i++){
        int x,y,w;cin>>x>>y>>w;
        upd.emplace_back(w,x,y);
    }
    for (int i=1;i<=q;i++){
        int x,y;cin>>x>>y;ans[i]=0;
        qry.emplace_back(x,y,i);
    }
    solve(upd,qry,0,1e9);
    for (int i=1;i<=q;i++)
        printf("%d\n",ans[i]);
}
int main(){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int T;cin>>T;while (T--) solve();return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 250ms
memory: 31348kb

input:

75
1000 1000
205432745 470548752 641881064
972832623 639054913 762973519
678871215 803867430 118261958
833419731 349421812 375017045
561177932 673829619 184524659
764937037 83708877 781504446
347223352 714500823 323457000
398512793 494262891 64649652
138888103 741302375 289501778
306141751 893073089...

output:

983867956
983867956
999931280
889687839
996335303
950644260
999931280
996335303
993151028
999931280
997021372
997021372
998805741
996335303
994277211
999931280
994277211
997021372
996335303
996335303
986381060
996335303
993475197
996335303
999931280
996335303
999931280
994277211
997021372
999931280
...

result:

ok 500000 lines