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>
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;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |