QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#41300 | #4421. Taxi | DaBenZhongXiaSongKuaiDi# | AC ✓ | 379ms | 9244kb | C++14 | 1.3kb | 2022-07-29 14:04:14 | 2022-07-29 14:04:14 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int maxn = (int)1e5+5;
int T,n,q; int val[4][maxn]; // min x+y x-y -x+y -x-y
struct Node{
int x,y,w;
bool operator < (const Node&T) const {return w > T.w;}
}a[maxn];
inline int getdis(int x,int y,int idx){
return max(x+y-val[0][idx],max(x-y-val[1][idx],max(-x+y-val[2][idx],-x-y-val[3][idx])));
}
signed main(){
scanf("%lld",&T);
while(T--){
scanf("%lld%lld",&n,&q);
for(int al=1;al<=n;al++) scanf("%lld%lld%lld",&a[al].x,&a[al].y,&a[al].w);
sort(a+1,a+n+1);
val[0][1] = a[1].x+a[1].y,
val[1][1] = a[1].x-a[1].y,
val[2][1] = -a[1].x+a[1].y,
val[3][1] = -a[1].x-a[1].y;
for(int al=2;al<=n;al++)
val[0][al] = min(val[0][al-1],a[al].x+a[al].y),
val[1][al] = min(val[1][al-1],a[al].x-a[al].y),
val[2][al] = min(val[2][al-1],-a[al].x+a[al].y),
val[3][al] = min(val[3][al-1],-a[al].x-a[al].y);
for(int al=1;al<=q;al++){
int A,B; scanf("%lld%lld",&A,&B);
if(getdis(A,B,n)<=a[n].w) {printf("%lld\n",getdis(A,B,n)); continue;}
if(getdis(A,B,1)>=a[1].w) {printf("%lld\n",a[1].w); continue;}
int l=1, r=n;
while(l+1<r){
int now = (l+r)>>1;
if(getdis(A,B,now)<=a[now].w) l=now;
else r=now;
}
printf("%lld\n",max(getdis(A,B,l),a[r].w));
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 379ms
memory: 9244kb
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