#include "bits/stdc++.h"
using namespace std;
#define task ""
#define ll long long
#define endl '\n'
#define fi first
#define se second
#define vall(a) (a).begin(), (a).end()
#define sze(a) (int)a.size()
#define pii pair<int, int>
#define pll pair<ll, ll>
#define ep emplace_back
#define pb push_back
#define pf push_front
const ll mod = 1e9 + 7;
const int N = 1e5 + 5;
const ll oo = 1e18;
bool START;
int n, m, w, h;
int sz[N], par[N];
int find(int v) {
return (v == par[v] ? v : par[v] = find(par[v]));
}
void merge(int a, int b) {
a = find(a);
b = find(b);
if (a != b) {
if (sz[a] < sz[b]) swap(a, b);
par[b] = a;
sz[a] += sz[b];
}
}
bool ligit(int a, int b) {
return find(a) == find(b);
}
double dist(ll x, ll y, ll u, ll v) {
return (double)sqrtl((x - u) * (x - u) + (y - v) * (y - v));
}
struct node {
ll x, y;
double rad;
node(int x_ = 0, int y_ = 0, double rad_ = 0) : x(x_), y(y_), rad(rad_) {}
bool operator<(const node &other) const {
return rad < other.rad;
}
};
node cor[1005];
vector<node> ds;
struct queries {
int idx, rad, id;
bool operator<(const queries &other) const {
return rad < other.rad;
}
} q[N];
string ans[N];
inline void solve() {
//n + 1, canh duoi
//n + 2, canh tren
//n + 3, canh trai
//n + 4, canh phai
for (int i = 1; i <= n; ++i) {
for (int j = i + 1; j <= n; ++j) {
ds.pb(node(i, j, (dist(cor[i].x, cor[i].y, cor[j].x, cor[j].y) - cor[i].rad - cor[j].rad)));
}
ds.pb(node(i, n + 1, cor[i].y - cor[i].rad));
ds.pb(node(i, n + 2, (h - cor[i].y) - cor[i].rad));
ds.pb(node(i, n + 3, cor[i].x - cor[i].rad));
ds.pb(node(i, n + 4, (w - cor[i].x) - cor[i].rad));
}
for (int i = 1; i <= n + 4; ++i) {
par[i] = i;
sz[i] = 1;
}
sort(vall(ds));
sort(q + 1, q + 1 + m);
int ptr = 0;
for (int i = 1; i <= m; ++i) {
auto[idx, rad, id] = q[i];
while(ptr < sze(ds) && ds[ptr].rad < 1.0 * (rad << 1)) {
merge(ds[ptr].x, ds[ptr].y);
++ptr;
}
if (idx == 1) {
if (ligit(n + 1, n + 3)) {
ans[id] += '1';
continue;
}
ans[id] += '1';
if (!ligit(n + 1, n + 2) && !ligit(n + 4, n + 1)) ans[id] += '2';
if (!ligit(n + 3, n + 4) && !ligit(n + 2, n + 4) && !ligit(n + 1, n + 2)) ans[id] += '3';
if (!ligit(n + 3, n + 4) && !ligit(n + 2, n + 3)) ans[id] += '4';
}
if (idx == 2) {
if (ligit(n + 1, n + 4)) {
ans[id] += '2';
continue;
}
if (!ligit(n + 1, n + 2) && !ligit(n + 3, n + 1)) ans[id] += '1';
ans[id] += '2';
if (!ligit(n + 3, n + 4) && !ligit(n + 2, n + 4)) ans[id] += '3';
if (!ligit(n + 3, n + 4) && !ligit(n + 2, n + 3) && ligit(n + 1, n + 2)) ans[id] += '4';
}
if (idx == 3) {
if (ligit(n + 2, n + 4)) {
ans[id] += '3';
continue;
}
if (!ligit(n + 3, n + 4) && !ligit(n + 1, n + 3) && ligit(n + 1, n + 2)) ans[id] += '1';
if (!ligit(n + 3, n + 4) && !ligit(n + 4, n + 1)) ans[id] += '2';
ans[id] += '3';
if (!ligit(n + 1, n + 2) && !ligit(n + 2, n + 3)) ans[id] += '4';
}
if (idx == 4) {
if (ligit(n + 2, n + 3)) {
ans[id] += '4';
continue;
}
if (!ligit(n + 3, n + 4) && !ligit(n + 3, n + 1)) ans[id] += '1';
if (!ligit(n + 3, n + 4) && !ligit(n + 1, n + 4) && ligit(n + 1, n + 2)) ans[id] += '2';
if (!ligit(n + 1, n + 2) && !ligit(n + 2, n + 4)) ans[id] += '3';
ans[id] += '4';
}
}
for (int i = 1; i <= m; ++i) cout << ans[i] << endl;
}
inline void input() {
cin >> n >> m >> w >> h;
for (int i = 1; i <= n; ++i) cin >> cor[i].x >> cor[i].y >> cor[i].rad;
for (int i = 1; i <= m; ++i) {
cin >> q[i].rad >> q[i].idx;
q[i].id = i;
}
return solve();
}
bool END;
int main() {
if(fopen(task ".inp", "r")) {
freopen(task ".inp", "r", stdin);
freopen(task ".out", "w", stdout);
}
ios_base::sync_with_stdio(false);
cin.tie(nullptr); cout.tie(nullptr);
input();
cerr << endl << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << 's' << endl;
cerr << "Memory: " << fabs ((&END - &START)) / 1048576.0 << "MB\n";
return 0;
}
Compilation message (stderr)
park.cpp: In function 'int main()':
park.cpp:171:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
171 | freopen(task ".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
park.cpp:172:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
172 | freopen(task ".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |