QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#42751#4421. Taxi01shijian#AC ✓366ms9004kbC++1.4kb2022-08-03 17:22:272022-08-03 17:22:30

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-08-03 17:22:30]
  • 评测
  • 测评结果:AC
  • 用时:366ms
  • 内存:9004kb
  • [2022-08-03 17:22:27]
  • 提交

answer

#include<bits/stdc++.h>
#define ios ios::sync_with_stdio(false); cin.tie(0), cout.tie(0)
#define int long long
using namespace std;
typedef long long LL;
const int N = 1e5 + 10,INF = INT_MAX;
int n,q;
struct Node
{
    int x,y,w;
    bool operator<(const Node &W) const
    {
        return w<W.w;
    }
}P[N];
//a:x+y,b:x-y,c:-x+y,d:-x-y
int a[N],b[N],c[N],d[N];

void solve()
{
    cin>>n>>q;
    for(int i=1;i<=n;i++) cin>>P[i].x>>P[i].y>>P[i].w;
    sort(P+1,P+n+1);
    a[n+1] = b[n+1] = c[n+1] = d[n+1] = -INF;
    for(int i=n;i;i--)
    {
        a[i] = max(a[i+1],P[i].x+P[i].y);
        b[i] = max(b[i+1],P[i].x-P[i].y);
        c[i] = max(c[i+1],-P[i].x+P[i].y);
        d[i] = max(d[i+1],-P[i].x-P[i].y);
    }
    while(q--)
    {
        int x,y;cin>>x>>y;
        int l = 1,r = n,ans = 0;
        while(l<r)
        {
            int mid = l + r + 1 >> 1;
            int res = max(max(-x-y+a[mid],-x+y+b[mid]),max(x-y+c[mid],x+y+d[mid]));
            if(P[mid].w<res) l = mid;
            else 
            {
                r = mid - 1;
                ans = max(ans,res);
            }
        }
        int res = max(max(-x-y+a[l],-x+y+b[l]),max(x-y+c[l],x+y+d[l]));
        if(P[l].w<res) ans = max(ans,P[l].w);
        else ans = max(ans,res);
        cout<<ans<<"\n";
    }
}

signed main()
{
    ios;
    int T;cin>>T;
    while(T--) solve();
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 366ms
memory: 9004kb

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