This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
// #pragma GCC optimize ("Ofast,unroll-loops")
// #pragma GCC target ("avx2")
using namespace std;
typedef long long ll;
typedef pair<int, int> pp;
#define er(args ...) cerr << __LINE__ << ": ", err(new istringstream(string(#args)), args), cerr << endl
#define per(i,r,l) for(int i = (r); i >= (l); i--)
#define rep(i,l,r) for(int i = (l); i < (r); i++)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define pb push_back
#define ss second
#define ff first
void err(istringstream *iss){}template<typename T,typename ...Args> void err(istringstream *iss,const T &_val, const Args&...args){string _name;*iss>>_name;if(_name.back()==',')_name.pop_back();cerr<<_name<<" = "<<_val<<", ",err(iss,args...);}
void IOS(){
cin.tie(0) -> sync_with_stdio(0);
// #ifndef ONLINE_JUDGE
// freopen("in.in", "r", stdin);
// freopen("out.out", "w", stdout);
// #endif
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const ll mod = 998244353, maxn = 5e3 + 5, lg = 22, inf = ll(1e9) + 5;
ll pw(ll a,ll b,ll md=mod){if(!b)return 1;ll k=pw(a,b>>1ll);return k*k%md*(b&1ll?a:1)%md;}
int par[maxn];
int get(int x){ return par[x] == -1? x: par[x] = get(par[x]); }
bool unite(int u, int v){
u = get(u), v = get(v);
if(u == v) return false;
par[v] = u; return true;
}
int n, q;
ll h, w, x[maxn], y[maxn], r[maxn];
ll fre[4][4];
ll sq(ll a){
ll s = max(0ll, ll(sqrt(a))-2);
while((s+1)*(s+1) <= a) s++;
return s;
}
ll dist(int a, int b){
if(a > b) swap(a, b);
if(b < n) return sq((x[a]-x[b])*(x[a]-x[b]) + (y[a]-y[b])*(y[a]-y[b])) - (r[a] + r[b]);
if(b == n) return y[a] - r[a];
if(b == n+1) return w - x[a] - r[a];
if(b == n+2) return h - y[a] - r[a];
return x[a] - r[a];
}
int main(){ IOS();
cin >> n >> q >> w >> h;
rep(i,0,n) cin >> x[i] >> y[i] >> r[i];
vector<pair<ll, pp>> edge{{inf, {n, n}}};
rep(i,0,n+4){
par[i] = -1;
rep(j,0,min(n,i)) edge.pb({dist(i, j), {i, j}});
}
sort(all(edge));
rep(i,0,4) rep(j,0,4) fre[i][j] = -1;
ll lst = edge[0].ff;
for(auto[w, p]: edge){
if(w - lst){
rep(i,0,4) rep(j,0,4) if(fre[i][j] == -1 && get(n+i) == get(n+j)) fre[i][j] = lst;
} lst = w;
auto[u, v] = p;
unite(u, v);
}
while(q--){
ll r, p; cin >> r >> p; r <<= 1ll, p--;
vector<int> ans{p};
if(min({fre[(p+0)%4][(p+1)%4], fre[(p+0)%4][(p+2)%4], fre[(p+0)%4][(p+3)%4]}) >= r) ans.pb((p+1)%4);
if(min({fre[(p+3)%4][(p+0)%4], fre[(p+3)%4][(p+1)%4], fre[(p+3)%4][(p+2)%4]}) >= r) ans.pb((p+3)%4);
if(min({fre[(p+0)%4][(p+2)%4], fre[(p+0)%4][(p+3)%4], fre[(p+1)%4][(p+3)%4], fre[(p+1)%4][(p+2)%4]}) >= r) ans.pb((p+2)%4);
sort(all(ans));
for(int c: ans) cout << c+1; cout << '\n';
}
return 0;
}
Compilation message (stderr)
park.cpp: In function 'int main()':
park.cpp:75:27: warning: narrowing conversion of 'p' from 'll' {aka 'long long int'} to 'int' [-Wnarrowing]
75 | vector<int> ans{p};
| ^
park.cpp:75:27: warning: narrowing conversion of 'p' from 'll' {aka 'long long int'} to 'int' [-Wnarrowing]
park.cpp:80:11: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
80 | for(int c: ans) cout << c+1; cout << '\n';
| ^~~
park.cpp:80:40: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
80 | for(int c: ans) cout << c+1; cout << '\n';
| ^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |