QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#41162 | #4421. Taxi | L1ngYu | AC ✓ | 167ms | 14692kb | C++20 | 1.8kb | 2022-07-28 15:24:57 | 2022-07-28 15:24:59 |
Judging History
answer
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<=b;++i)
#define per(i,a,b) for(int i=a;i>=b;--i)
#define forr(i,a) for(auto i:a)
#define all(a) begin(a),end(a)
#define rall(a) rbegin(a),rend(a)
#define pb emplace_back
using namespace std;
struct read
{
static const int M = 1 << 23;
char buf[M], *S = buf, *P = buf, c, l;
inline char gc() { return (S == P && (P = (S = buf) + fread(buf, 1, M, stdin), S == P) ? EOF : *S++); }
template<class T> inline read &operator>>(T &x)
{
for (c = 0;!isdigit(c);c = gc()) l = c;
for (x = 0;isdigit(c);c = gc()) x = x * 10 + (c & 15);
return x = (l ^ 45) ? x : -x, *this;
}
}Cin;
struct T
{
int x, y, w;
bool operator<(T &_) { return w < _.w; }
};
constexpr int N = 1e5 + 10;
T a[N]; int mx[N][4];
void solve()
{
int n, q; Cin >> n >> q;
rep(i, 1, n)
{
auto &[x, y, w] = a[i];
Cin >> x >> y >> w;
}
sort(a + 1, a + n + 1);
memset(mx[n + 1], -0x3f, sizeof(mx[n + 1]));
per(i, n, 1)
{
auto &[x, y, w] = a[i];
mx[i][0] = max(mx[i + 1][0], x + y);
mx[i][1] = max(mx[i + 1][1], x - y);
mx[i][2] = max(mx[i + 1][2], -x + y);
mx[i][3] = max(mx[i + 1][3], -x - y);
}
for (int x, y;q--;)
{
Cin >> x >> y;
int l = 1, r = n, ret = INT_MIN;
while (l <= r)
{
int mid = l + r >> 1,
cur = max({ x + y + mx[mid][3], x - y + mx[mid][2], -x + y + mx[mid][1], -x - y + mx[mid][0] });
auto &[X, Y, W] = a[mid];
if (cur <= W) r = mid - 1, ret = max(ret, cur);
else l = mid + 1, ret = max(ret, W);
}
printf("%d\n", ret);
}
}
signed main()
{
int _;for (Cin >> _; _--;) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 167ms
memory: 14692kb
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