#include <bits/stdc++.h>
using namespace std;
/// 4
/// 1 3
/// 2
const int maxN = 1e5 + 5;
int x[maxN], y[maxN], w[maxN], Qw[maxN], Qe[maxN], res[maxN], check[5][5];
int par[2010], sz[2010];
pair<int, int> save[4000005];
vector<pair<int, double>> event;
bool cmp (pair<int, double> A, pair<int, double> B) {
if (A.second != B.second) return A.second < B.second;
return A.first < B.first;
}
double cal_dis(int i, int j) {
double len = 1LL * (x[i] - x[j]) * (x[i] - x[j]) + 1LL * (y[i] - y[j]) * (y[i] - y[j]); len = sqrt(len);
return len - w[i] - w[j];
}
int find_set(int u) {
return (u == par[u]) ? u : par[u] = find_set(par[u]);
}
void union_set(int u, int v) {
u = find_set(u);
v = find_set(v);
if (u == v) return ;
if (sz[u] < sz[v]) swap(u, v);
par[v] = u;
sz[u] += sz[v];
}
void update_state(int n) {
/// 1 -> 2
if (find_set(n + 1) == find_set(n + 2)) {
check[1][2] = check[1][3] = check[1][4] = 0;
check[2][1] = check[3][1] = check[4][1] = 0;
}
if (find_set(n + 2) == find_set(n + 3)) {
check[2][1] = check[2][3] = check[2][4] = 0;
check[1][2] = check[3][2] = check[4][2] = 0;
}
if (find_set(n + 3) == find_set(n + 4)) {
check[3][1] = check[3][2] = check[3][4] = 0;
check[1][3] = check[2][3] = check[4][3] = 0;
}
if (find_set(n + 4) == find_set(n + 1)) {
check[4][1] = check[4][2] = check[4][3] = 0;
check[1][4] = check[2][4] = check[3][4] = 0;
}
if (find_set(n + 1) == find_set(n + 3)) {
check[1][4] = check[1][3] = check[2][4] = check[2][3] = 0;
check[4][1] = check[3][1] = check[4][2] = check[3][2] = 0;
}
if (find_set(n + 2) == find_set(n + 4)) {
check[1][2] = check[1][3] = check[4][2] = check[4][3] = 0;
check[2][1] = check[3][1] = check[2][4] = check[3][4] = 0;
}
}
int main() {
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int n, q, X, Y, m = 0;
cin >> n >> q >> X >> Y;
for (int i = 1; i <= n; i++)
cin >> x[i] >> y[i] >> w[i];
for (int i = 1; i <= n; i++) {
for (int j = i + 1; j <= n; j++) {
event.push_back({++m, cal_dis(i, j)});
save[m] = {i, j};
}
event.push_back({++m, (x[i] - w[i])}); save[m] = {i, n + 1};
event.push_back({++m, (y[i] - w[i])}); save[m] = {i, n + 2};
event.push_back({++m, (X - x[i] - w[i])}); save[m] = {i, n + 3};
event.push_back({++m, (Y - y[i] - w[i])}); save[m] = {i, n + 4};
}
for (int i = 1; i <= q; i++) {
cin >> Qw[i] >> Qe[i];
event.push_back({-i, 2 * Qw[i]});
}
for (int i = 1; i <= 4; i++)
for (int j = 1; j <= 4; j++)
check[i][j] = j;
sort(event.begin(), event.end(), cmp);
for (int i = 1; i <= n + 4; i++) {
par[i] = i;
sz[i] = 1;
}
for (auto it: event) {
int id = it.first;
if (id > 0) {
auto [u, v] = save[id];
union_set(u, v);
}
else {
id = abs(id);
update_state(n);
int ans = 0;
for (int i = 1; i <= 4; i++)
if (check[Qe[id]][i]) ans = ans * 10 + check[Qe[id]][i];
res[id] = ans;
}
}
for (int i = 1; i <= q; i++)
cout << res[i] << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
348 ms |
51888 KB |
Output is correct |
2 |
Correct |
358 ms |
51884 KB |
Output is correct |
3 |
Correct |
345 ms |
52076 KB |
Output is correct |
4 |
Correct |
346 ms |
51880 KB |
Output is correct |
5 |
Correct |
350 ms |
52036 KB |
Output is correct |
6 |
Correct |
338 ms |
51888 KB |
Output is correct |
7 |
Correct |
313 ms |
52144 KB |
Output is correct |
8 |
Correct |
320 ms |
51884 KB |
Output is correct |
9 |
Correct |
1 ms |
2384 KB |
Output is correct |
10 |
Correct |
1 ms |
2384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
41 ms |
5836 KB |
Output is correct |
2 |
Correct |
36 ms |
5744 KB |
Output is correct |
3 |
Correct |
36 ms |
5836 KB |
Output is correct |
4 |
Correct |
35 ms |
5836 KB |
Output is correct |
5 |
Correct |
36 ms |
5836 KB |
Output is correct |
6 |
Correct |
35 ms |
5836 KB |
Output is correct |
7 |
Correct |
33 ms |
5580 KB |
Output is correct |
8 |
Correct |
33 ms |
5580 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
348 ms |
51888 KB |
Output is correct |
2 |
Correct |
358 ms |
51884 KB |
Output is correct |
3 |
Correct |
345 ms |
52076 KB |
Output is correct |
4 |
Correct |
346 ms |
51880 KB |
Output is correct |
5 |
Correct |
350 ms |
52036 KB |
Output is correct |
6 |
Correct |
338 ms |
51888 KB |
Output is correct |
7 |
Correct |
313 ms |
52144 KB |
Output is correct |
8 |
Correct |
320 ms |
51884 KB |
Output is correct |
9 |
Correct |
1 ms |
2384 KB |
Output is correct |
10 |
Correct |
1 ms |
2384 KB |
Output is correct |
11 |
Correct |
41 ms |
5836 KB |
Output is correct |
12 |
Correct |
36 ms |
5744 KB |
Output is correct |
13 |
Correct |
36 ms |
5836 KB |
Output is correct |
14 |
Correct |
35 ms |
5836 KB |
Output is correct |
15 |
Correct |
36 ms |
5836 KB |
Output is correct |
16 |
Correct |
35 ms |
5836 KB |
Output is correct |
17 |
Correct |
33 ms |
5580 KB |
Output is correct |
18 |
Correct |
33 ms |
5580 KB |
Output is correct |
19 |
Correct |
370 ms |
86960 KB |
Output is correct |
20 |
Correct |
362 ms |
86960 KB |
Output is correct |
21 |
Correct |
368 ms |
86948 KB |
Output is correct |
22 |
Correct |
355 ms |
86948 KB |
Output is correct |
23 |
Correct |
361 ms |
86948 KB |
Output is correct |
24 |
Correct |
339 ms |
86948 KB |
Output is correct |