QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#59287 | #4421. Taxi | qinjianbin | AC ✓ | 526ms | 7988kb | C++ | 6.1kb | 2022-10-28 23:11:51 | 2022-10-28 23:11:53 |
Judging History
answer
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<ctime>
#include<queue>
#include<stack>
#include<deque>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<bitset>
#include<functional>
using namespace std;
//STL库常用(vector, map, set, pair)
#define pii pair<int,int>
#define pdd pair<double,double>
#define F first
#define S second
//常量
#define PI (acos(-1.0))
#define INF 0x3f3f3f3f
//必加
#ifdef TanJI
#include<cassert>
#define dbg(...) do {cerr << "\033[33;1m" << #__VA_ARGS__ << " -> "; err(__VA_ARGS__); } while(0)
void err() {cerr << "\033[39;0m" << endl;}
template<template<typename...> class T, typename t, typename... A> void err(T<t> a, A... x) {for (auto v: a) cerr << v << ' '; cerr << ", "; err(x...);}
template<typename T, typename... A> void err(T a, A... x) {cerr << a << ' '; err(x...);}
template<typename T> void err(T *a, int len) {for (int i = 0; i < len; i++) cerr << a[i] << ' '; err();}
#else
#define dbg(...)
#define assert(...)
#endif
typedef unsigned long long ull;
typedef long long ll;
typedef double db;
// 快读快输
template<typename T> inline T read() {T x=0; bool f=0; char c=getchar();while(!isdigit(c)){if(c =='-')f= 1; c=getchar();}while(isdigit(c)){x=(x<<3)+(x<<1)+(c^48);c=getchar();}return f?~x+1:x;}
template<typename T> inline void print(T k){ int num = 0,ch[20]; if(k == 0){ putchar('0'); return ; } (k<0)&&(putchar('-'),k = -k); while(k>0) ch[++num] = k%10, k /= 10; while(num) putchar(ch[num--]+48); }
//图论
const int GRAPHN = 1, GRAPHM = 1;
int h[GRAPHN], e[GRAPHM], ne[GRAPHM], wei[GRAPHM], idx;
void AddEdge(int a, int b) {e[idx] = b, ne[idx] = h[a], h[a] = idx++;}
void AddEdge(int a, int b, int c) {e[idx] = b, ne[idx] = h[a], wei[idx] = c, h[a] = idx++;}
void AddEdge(int h[], int a, int b) {e[idx] = b, ne[idx] = h[a], h[a] = idx++;}
void AddEdge(int h[], int a, int b, int c) {e[idx] = b, ne[idx] = h[a], wei[idx] = c, h[a] = idx++;}
// 数学公式
template<typename T> inline T gcd(T a, T b){ return b==0 ? a : gcd(b,a%b); }
template<typename T> inline T lowbit(T x){ return x&(-x); }
template<typename T> inline bool mishu(T x){ return x>0?(x&(x-1))==0:false; }
template<typename T1,typename T2, typename T3> inline ll q_mul(T1 a,T2 b,T3 p){ ll w = 0; while(b){ if(b&1) w = (w+a)%p; b>>=1; a = (a+a)%p; } return w; }
template<typename T,typename T2> inline ll f_mul(T a,T b,T2 p){ return (a*b - (ll)((long double)a/p*b)*p+p)%p; }
template<typename T1,typename T2, typename T3> inline ll q_pow(T1 a,T2 b,T3 p){ ll w = 1; while(b){ if(b&1) w = (w*a)%p; b>>=1; a = (a*a)%p;} return w; }
template<typename T1,typename T2, typename T3> inline ll s_pow(T1 a,T2 b,T3 p){ ll w = 1; while(b){ if(b&1) w = q_mul(w,a,p); b>>=1; a = q_mul(a,a,p);} return w; }
template<typename T> inline ll ex_gcd(T a, T b, T& x, T& y){ if(b == 0){ x = 1, y = 0; return (ll)a; } ll r = ex_gcd(b,a%b,y,x); y -= a/b*x; return r;/*gcd*/ }
template<typename T1,typename T2> inline ll com(T1 m, T2 n) { int k = 1;ll ans = 1; while(k <= n){ ans=((m-k+1)*ans)/k;k++;} return ans; }
template<typename T> inline bool isprime(T n){ if(n <= 3) return n>1; if(n%6 != 1 && n%6 != 5) return 0; T n_s = floor(sqrt((db)(n))); for(int i = 5; i <= n_s; i += 6){ if(n%i == 0 || n%(i+2) == 0) return 0; } return 1; }
/* ----------------------------------------------------------------------------------------------------------------------------------------------------------------- */
const int MAXN = 1e5 + 10;
int T;
int n, q;
int x[MAXN], y[MAXN], w[MAXN];
struct Node {
int w, d;
bool operator< (const Node &a) {
return w < a.w;
}
}que[4][MAXN];
bool Check(int idx, int mid, int val) {
int tmp = que[idx][mid].d + val;
if (tmp > que[idx][mid].w) return 1;
return 0;
}
int main() {
#ifdef TanJI
clock_t c1 = clock();
freopen("D:\\Cpp\\1.in", "r", stdin);
freopen("D:\\Cpp\\1.out", "w", stdout);
#endif
//--------------------------------------------
scanf("%d", &T);
while (T--) {
scanf("%d%d", &n, &q);
for (int i = 1; i <= n; i++)
scanf("%d%d%d", &x[i], &y[i], &w[i]);
for (int i = 1; i <= n; i++) {
que[0][i] = {w[i], x[i] + y[i]};
que[1][i] = {w[i], x[i] - y[i]};
que[2][i] = {w[i], -x[i] + y[i]};
que[3][i] = {w[i], -x[i] - y[i]};
}
for (int i = 0; i < 4; i++) {
sort(que[i] + 1, que[i] + 1 + n);
int siz = 0;
for (int j = 1; j <= n; j++) {
while (siz != 0 && que[i][siz].d <= que[i][j].d) siz--;
que[i][++siz] = que[i][j];
}
que[i][0].d = siz;
// for (int j = 1; j <= siz; j++)
// printf("%d %d\n", que[i][j].d, que[i][j].w);
}
int x, y;
for (int i = 1; i <= q; i++) {
scanf("%d%d", &x, &y);
int ans = 0;
for (int j = 0; j < 4; j++) {
int val;
if (j == 0) val = -x - y;
else if (j == 1) val = -x + y;
else if (j == 2) val = x - y;
else val = x + y;
int l = 1, r = que[j][0].d + 1;
while (l < r) {
int mid = l + r >> 1;
if (Check(j, mid, val)) l = mid + 1;
else r = mid;
}
if (l == que[j][0].d + 1)
ans = max(ans, min(que[j][l - 1].w, que[j][l - 1].d + val));
else if (l == 1)
ans = max(ans, min(que[j][l].w, que[j][l].d + val));
else
ans = max({ans, min(que[j][l].w, que[j][l].d + val), min(que[j][l - 1].w, que[j][l - 1].d + val)});
// printf("%d %d %d %d\n", i, l, val, ans);
}
printf("%d\n", ans);
}
}
//--------------------------------------------
#ifdef TanJI
cerr << "Time Used:" << clock() - c1 << "ms" << endl;
#endif
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 526ms
memory: 7988kb
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