#include <bits/stdc++.h>
using namespace std;
using db = long double;
using ll = long long;
using pl = pair<ll, ll>;
using pi = pair<int, int>;
#define vt vector
#define f first
#define s second
#define pb push_back
#define all(x) x.begin(), x.end()
#define size(x) ((int) (x).size())
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define ROF(i, a, b) for (int i = (b) - 1; i >= (a); i--)
#define F0R(i, b) FOR (i, 0, b)
#define endl '\n'
const ll INF = 1e18;
const int inf = 1e9;
template<typename... Args> // tuples
ostream& operator<<(ostream& os, tuple<Args...> t) {
apply([&](Args... args) { string dlm = "{"; ((os << dlm << args, dlm = ", "), ...); }, t);
return os << "}";
}
template<typename T, typename V> // pairs
ostream& operator<<(ostream& os, pair<T, V> p) { return os << "{" << p.f << ", " << p.s << "}"; }
template<class T, class = decltype(begin(declval<T>()))> // iterables
typename enable_if<!is_same<T, string>::value, ostream&>::type operator<<(ostream& os, const T& v) {
string dlm = "{";
for (auto& i : v) os << dlm << i, dlm = ", ";
return os << "}";
}
template <typename T, typename... V>
void printer(string pfx, const char *names, T&& head, V&& ...tail) {
int i = 0;
while (names[i] && names[i] != ',') i++;
constexpr bool is_str = is_same_v<decay_t<T>, const char*>;
if (is_str) cerr << " " << head;
else cerr << pfx, cerr.write(names, i) << " = " << head;
if constexpr (sizeof...(tail)) printer(is_str ? "" : ",", names + i + 1, tail...);
else cerr << endl;
}
#ifdef LOCAL
#define dbg(...) printer(to_string(__LINE__) + ": ", #__VA_ARGS__, __VA_ARGS__)
#else
#define dbg(x...)
#define cerr if (0) std::cerr
#endif
/*
answer queries in increasing radius of visitors
we can consider increasing the radius of visitors as expanding trees and pushing inwards the sides of the rectangle
this way, visitors are always points
for each pair of trees, there will be some radius such that the "gap" between them is filled
if we consider the walls and trees as nodes, if two opposing walls belong to the same connected component, then you cant go between them
we can do dsu and just spam stuff to check
*/
#define sq(x) ((x) * (x))
struct DSU {
vt<int> e;
void init(int n) {
e.resize(n, -1);
}
int find(int x) { return e[x] < 0 ? x : e[x] = find(e[x]); }
void unite(int x, int y) {
x = find(x), y = find(y);
if (x == y) return;
if (e[x] < e[y]) swap(x, y);
e[y] += e[x];
e[x] = y;
}
bool same_set(int u, int v) {
return find(u) == find(v);
}
};
ll floor_sqrt(ll x) {
ll y = sqrt(x);
while (y * y < x) y++;
while (y * y > x) y--;
return y;
}
struct Tree {
ll x, y, r;
};
int n, q;
ll w, h;
map<ll, pair< vt<pl>, vt<pl> >> evs; // radius -> {{set of edges}, {queries}}
vt<vt<int>> ans;
vt<Tree> trees;
// neighbour walls of each thingy
// walls are indexed starting from right, anticlockwise
vt<vt<int>> adj {
{2, 3},
{0, 3},
{0, 1},
{1, 2}
};
main() {
cin.tie(0)->sync_with_stdio(0);
cin >> n >> q >> w >> h;
ans.resize(q);
trees.resize(n);
F0R (i, n) {
cin >> trees[i].x >> trees[i].y >> trees[i].r;
}
F0R (i, q) {
ll r, s; cin >> r >> s;
evs[2 * r].s.pb({s - 1, i});
}
F0R (i, n) {
FOR (j, i + 1, n) {
ll dist = floor_sqrt(sq(trees[i].x - trees[j].x) + sq(trees[i].y - trees[j].y)) - trees[i].r - trees[j].r;
dbg(i, j, dist + 1);
evs[dist + 1].f.pb({i, j});
}
}
F0R (i, n) {
// right
evs[w - trees[i].x - trees[i].r + 1].f.pb({i, n});
// top
evs[h - trees[i].y - trees[i].r + 1].f.pb({i, n + 1});
// left
evs[trees[i].x - trees[i].r + 1].f.pb({i, n + 2});
// bot
evs[trees[i].y - trees[i].r + 1].f.pb({i, n + 3});
}
DSU dsu;
dsu.init(n + 4);
for (auto& [r, todo] : evs) {
auto& [edges, queries] = todo;
for (auto [u, v] : edges) {
dsu.unite(u, v);
}
for (auto [s, qi] : queries) {
F0R (i, 4) {
bool good = true;
if (s != i) {
if ((i - s + 4) % 4 == 2) {
// opposite
for (int x : adj[(s + 1) % 4]) {
for (int y : adj[(i + 1) % 4]) {
good &= !dsu.same_set(n + x, n + y);
}
}
} else {
// adjacent
int com = -1; // common wall
for (int x : adj[s]) for (int y : adj[i]) if (x == y) com = x;
F0R (j, 4) {
if (j != com) good &= !dsu.same_set(n + j, n + com);
}
}
}
if (good) ans[qi].pb(i);
}
}
}
for (auto& poss : ans) {
sort(all(poss));
for (int x : poss) cout << x + 1;
cout << endl;
}
}
Compilation message
park.cpp:115:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
115 | main() {
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2175 ms |
251412 KB |
Output is correct |
2 |
Correct |
2158 ms |
251472 KB |
Output is correct |
3 |
Correct |
2162 ms |
251472 KB |
Output is correct |
4 |
Correct |
2149 ms |
251472 KB |
Output is correct |
5 |
Correct |
2085 ms |
251392 KB |
Output is correct |
6 |
Correct |
2159 ms |
251364 KB |
Output is correct |
7 |
Correct |
1736 ms |
250948 KB |
Output is correct |
8 |
Correct |
1702 ms |
250980 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
58 ms |
15332 KB |
Output is correct |
2 |
Correct |
60 ms |
17384 KB |
Output is correct |
3 |
Correct |
57 ms |
15700 KB |
Output is correct |
4 |
Correct |
63 ms |
17492 KB |
Output is correct |
5 |
Correct |
61 ms |
17748 KB |
Output is correct |
6 |
Correct |
56 ms |
17232 KB |
Output is correct |
7 |
Correct |
49 ms |
14524 KB |
Output is correct |
8 |
Correct |
48 ms |
14512 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2175 ms |
251412 KB |
Output is correct |
2 |
Correct |
2158 ms |
251472 KB |
Output is correct |
3 |
Correct |
2162 ms |
251472 KB |
Output is correct |
4 |
Correct |
2149 ms |
251472 KB |
Output is correct |
5 |
Correct |
2085 ms |
251392 KB |
Output is correct |
6 |
Correct |
2159 ms |
251364 KB |
Output is correct |
7 |
Correct |
1736 ms |
250948 KB |
Output is correct |
8 |
Correct |
1702 ms |
250980 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
58 ms |
15332 KB |
Output is correct |
12 |
Correct |
60 ms |
17384 KB |
Output is correct |
13 |
Correct |
57 ms |
15700 KB |
Output is correct |
14 |
Correct |
63 ms |
17492 KB |
Output is correct |
15 |
Correct |
61 ms |
17748 KB |
Output is correct |
16 |
Correct |
56 ms |
17232 KB |
Output is correct |
17 |
Correct |
49 ms |
14524 KB |
Output is correct |
18 |
Correct |
48 ms |
14512 KB |
Output is correct |
19 |
Runtime error |
1664 ms |
262144 KB |
Execution killed with signal 9 |
20 |
Halted |
0 ms |
0 KB |
- |