QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#112609 | #4421. Taxi | Tobo | AC ✓ | 916ms | 6312kb | C++20 | 1.6kb | 2023-06-12 15:41:35 | 2023-06-12 15:41:37 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF=0x3f3f3f3f;
int T,n,q,xi,yi,wi;
int qx,qy;
vector< array<int,3> > vt;
vector<int> b;
vector<int> m1,m2,m3,m4;
bool check(int k)
{
if(k>vt[n][0]) return false;
int idx=lower_bound(b.begin()+1,b.begin()+1+n,k)-b.begin();
int d = max ( max ( max(qx+qy+m4[idx],qx-qy+m3[idx]),-qx+qy+m2[idx] ), -qx-qy+m1[idx] );
if(k<=d) return true;
return false;
}
void solve()
{
cin>>n>>q;
vt.clear(); vt.resize(n+1);
b.clear(); b.resize(n+10);
for(int i=1;i<=n;i++)
{
cin>>xi>>yi>>wi;
vt[i][0]=wi; vt[i][1]=xi; vt[i][2]=yi;
b[i]=vt[i][0];
}
sort(vt.begin(),vt.end());
sort(b.begin()+1,b.begin()+1+n);
m1.clear(); m1.resize(n+5); m1.assign(n+5,-INF);
m2.clear(); m2.resize(n+5); m2.assign(n+5,-INF);
m3.clear(); m3.resize(n+5); m3.assign(n+5,-INF);
m4.clear(); m4.resize(n+5); m4.assign(n+5,-INF);
for(int i=n;i>=1;i--)
{
m1[i] = max( m1[i+1] , vt[i][1]+vt[i][2] ) ;
m2[i] = max( m2[i+1] , vt[i][1]-vt[i][2] ) ;
m3[i] = max( m3[i+1] , -vt[i][1]+vt[i][2]) ;
m4[i] = max( m4[i+1] , -vt[i][1]-vt[i][2]) ;
}
for(int i=1;i<=q;i++)
{
cin>>qx>>qy;
int l=0,r=INF,mid;
while(l<r)
{
mid=(l+r+1)/2;
if(check(mid)) l=mid;
else r=mid-1;
}
cout<<l<<'\n';
}
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin>>T;
while(T--)
{
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 916ms
memory: 6312kb
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