QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#41161 | #4421. Taxi | L1ngYu | AC ✓ | 172ms | 14668kb | C++20 | 1.8kb | 2022-07-28 15:23:33 | 2022-07-28 15:23:33 |
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;
static const int M = 1 << 23;
static char buf[M], *S = buf, *P = buf, c, l;
struct read
{
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);
}
cout << ret << '\n';
}
}
signed main()
{
cin.tie(0)->sync_with_stdio(0);
int _;for (Cin >> _; _--;) solve();
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 172ms
memory: 14668kb
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