이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
}
}
컴파일 시 표준 에러 (stderr) 메시지
park.cpp:115:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
115 | main() {
| ^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |