This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//#pragma optimize("Ofast")
//#pragma optimize("unroll-loops")
//#pragma traget("avx,avx2")
#include <iostream>
#include <cmath>
#include <algorithm>
#include <stdio.h>
#include <cstdint>
#include <cstring>
#include <string>
#include <cstdlib>
#include <vector>
#include <bitset>
#include <map>
#include <queue>
#include <ctime>
#include <stack>
#include <set>
#include <list>
#include <random>
#include <deque>
#include <functional>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <complex>
#include <numeric>
#include <cassert>
#include <array>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <thread>
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define el '\n'
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define point pair <ll, ll>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
using namespace std;
#include <random>
mt19937 rnd(time(0));
const ll INF = 1e18 + 10;
const ll inf = 1e9 + 10;
const ll N = 2e3 + 10;
const ll mod = 998244353;
const ll LOG = 22;
const ll K = 1e3 + 20;
ll x[N], y[N], r[N];
ll parent[N], sz[N];
void build(ll n) {
for (ll i = 1; i <= n; i++)
parent[i] = i, sz[i] = 1;
}
ll lead(ll v) {
if (parent[v] == v)
return v;
return parent[v] = lead(parent[v]);
}
void union_sets(ll a, ll b) {
a = lead(a);
b = lead(b);
if (a != b) {
if (sz[a] < sz[b])
swap(a, b);
sz[a] += sz[b];
parent[b] = a;
}
}
void solve() {
ll n, m, w, h;
cin >> n >> m >> w >> h;
vector <pair <ll, pair <ll, ll>>> edges;
for (ll i = 1; i <= n; i++) {
cin >> x[i] >> y[i] >> r[i];
for (ll j = 1; j < i; j++) {
ll distance = abs(x[i] - x[j]) * abs(x[i] - x[j]) +
abs(y[i] - y[j]) * abs(y[i] - y[j]);
distance = sqrtl(distance) - r[i] - r[j];
edges.pb({distance, {i, j}});
}
edges.pb({x[i] - r[i], {i, n + 1}});
edges.pb({y[i] - r[i], {i, n + 2}});
edges.pb({w - x[i] - r[i], {i, n + 3}});
edges.pb({h - y[i] - r[i], {i, n + 4}});
}
sort(all(edges));
build(n + 4);
ll mx[5][5];
for (ll i = 1; i <= 4; i++)
for (ll j = 1; j <= 4; j++)
mx[i][j] = inf;
for (ll i = 0; i < edges.size(); i++) {
union_sets(edges[i].ss.ff, edges[i].ss.ss);
for (ll j = 1; j <= 4; j++)
for (ll k = 1; k <= 4; k++)
if (lead(n + j) == lead(n + k))
mx[j][k] = min(mx[j][k], edges[i].ff);
}
while (m--) {
ll rad, e;
cin >> rad >> e;
ll d = 2 * rad;
if (e == 1) {
if (d > mx[1][2])
cout << 1 << el;
else if (d > mx[1][3])
cout << 12 << el;
else if (d > mx[2][4])
cout << 14 << el;
else if (d > mx[2][3])
cout << 134 << el;
else if (d > mx[3][4])
cout << 124 << el;
else if (d > mx[1][4])
cout << 123 << el;
else
cout << 1234 << el;
} else if (e == 2) {
if (d > mx[2][3])
cout << 2 << el;
else if (d > mx[1][3])
cout << 12 << el;
else if (d > mx[2][4])
cout << 23 << el;
else if (d > mx[1][2])
cout << 234 << el;
else if (d > mx[3][4])
cout << 124 << el;
else if (d > mx[1][4])
cout << 123 << el;
else
cout << 1234 << el;
} else if (e == 3) {
if (d > mx[3][4])
cout << 3 << el;
else if (d > mx[1][3])
cout << 34 << el;
else if (d > mx[2][4])
cout << 23 << el;
else if (d > mx[1][2])
cout << 234 << el;
else if (d > mx[2][3])
cout << 134 << el;
else if (d > mx[1][4])
cout << 123 << el;
else
cout << 1234 << el;
} else {
if (d > mx[4][1])
cout << 4 << el;
else if (d > mx[1][3])
cout << 34 << el;
else if (d > mx[2][4])
cout << 14 << el;
else if (d > mx[1][2])
cout << 234 << el;
else if (d > mx[2][3])
cout << 134 << el;
else if (d > mx[3][4])
cout << 124 << el;
else
cout << 1234 << el;
}
}
return;
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int tests = 1;
//cin >> tests;
while (tests--)
solve();
return 0;
}
/*
*/
Compilation message (stderr)
park.cpp: In function 'void solve()':
park.cpp:117:22: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::pair<long long int, std::pair<long long int, long long int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
117 | for (ll i = 0; i < edges.size(); i++) {
| ~~^~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |