/**
* author : pham van sam
* created : 13 June 2023 (Tuesday)
**/
#include <bits/stdc++.h>
using namespace std;
using namespace chrono;
#define int long long
#define MASK(x) (1LL << (x))
#define BIT(x, i) (((x) >> (i)) & 1)
#define ALL(x) (x).begin(), (x).end()
#define REP(i, n) for (int i = 0, _n = n; i < _n; ++i)
#define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i)
#define FORD(i, a, b) for (int i = (a), _b = (b); i >= _b; --i)
#define FORE(it, s) for (__typeof(s.begin()) it = (s).begin(); it != (s).end(); ++it)
template <typename U, typename V> bool maximize(U &A, const V &B) { return (A < B) ? (A = B, true) : false; }
template <typename U, typename V> bool minimize(U &A, const V &B) { return (A > B) ? (A = B, true) : false; }
const int MAXN = 3e5 + 5;
int N, ans[MAXN], ID[MAXN];
long long sqr(long long x) { return x * x; }
struct Circle_t {
int x, y, r; // coordinate and radius
Circle_t (int x = 0, int y = 0, int r = 0) : x(x), y(y), r(r) {}
bool intersect(const Circle_t &a) const {
return sqr(x - a.x) + sqr(y - a.y) <= sqr(r + a.r);
}
} a[MAXN];
const int MAX = 1e9, INF = 2e9 + 7;
unordered_map <long long, vector <int>> mp;
void rescaling_grid(int sz) {
mp.clear();
FOR(i, 1, N) if(ans[i] == 0) {
int x = a[i].x / sz, y = a[i].y / sz;
long long tmp = 1LL * x * INF + y;
mp[tmp].push_back(i);
}
}
void eliminator(long long pos, int u) {
if(!mp.count(pos)) return;
vector <int> &points = mp[pos];
for (int i = 0; i < (int) points.size(); ++i) {
if(a[points[i]].intersect(a[u])) {
ans[points[i]] = u;
swap(points[i--], points.back());
points.pop_back();
}
}
if(points.empty()) mp.erase(pos);
}
void process(void) {
cin >> N;
FOR(i, 1, N) {
cin >> a[i].x >> a[i].y >> a[i].r;
a[i].x += MAX;
a[i].y += MAX;
}
iota(ID + 1, ID + N + 1, 1);
sort(ID + 1, ID + N + 1, [&] (int i, int j) {
return (a[i].r > a[j].r || (a[i].r == a[j].r && i < j));
});
int rMax = 1e9;
FOR(i, 1, N) {
int u = ID[i];
if(ans[u]) continue;
if(a[u].r < rMax / 2) {
rMax = a[u].r;
rescaling_grid(rMax);
}
FOR(cx, a[u].x / rMax - 2, a[u].x / rMax + 2) {
FOR(cy, a[u].y / rMax - 2, a[u].y / rMax + 2) {
eliminator(1LL * cx * INF + cy, u);
}
}
}
FOR(i, 1, N) cout << ans[i] << " \n"[i == N];
}
signed main() {
#define TASK "TASK"
if(fopen(TASK".inp", "r")) {
freopen(TASK".inp", "r", stdin);
freopen(TASK".out", "w", stdout);
}
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
auto start_time = steady_clock::now();
int test = 1;
// cin >> test;
for (int i = 1; i <= test; ++i) {
process();
// cout << '\n';
}
auto end_time = steady_clock::now();
cerr << "\nExecution time : " << duration_cast<milliseconds> (end_time - start_time).count() << "[ms]" << endl;
return (0 ^ 0);
}
Compilation message
circle_selection.cpp: In function 'int main()':
circle_selection.cpp:96:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
96 | freopen(TASK".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
circle_selection.cpp:97:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
97 | freopen(TASK".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
7380 KB |
Output is correct |
2 |
Correct |
5 ms |
7380 KB |
Output is correct |
3 |
Correct |
4 ms |
7380 KB |
Output is correct |
4 |
Correct |
4 ms |
7380 KB |
Output is correct |
5 |
Correct |
3 ms |
7380 KB |
Output is correct |
6 |
Incorrect |
3 ms |
7380 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
166 ms |
14512 KB |
Output is correct |
2 |
Correct |
157 ms |
14508 KB |
Output is correct |
3 |
Correct |
149 ms |
14496 KB |
Output is correct |
4 |
Incorrect |
215 ms |
14644 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
7380 KB |
Output is correct |
2 |
Correct |
234 ms |
18612 KB |
Output is correct |
3 |
Correct |
936 ms |
40200 KB |
Output is correct |
4 |
Correct |
934 ms |
40228 KB |
Output is correct |
5 |
Correct |
922 ms |
35732 KB |
Output is correct |
6 |
Correct |
316 ms |
21052 KB |
Output is correct |
7 |
Correct |
138 ms |
14684 KB |
Output is correct |
8 |
Correct |
22 ms |
8908 KB |
Output is correct |
9 |
Correct |
1010 ms |
39712 KB |
Output is correct |
10 |
Correct |
687 ms |
34804 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
693 ms |
40252 KB |
Output is correct |
2 |
Correct |
645 ms |
40260 KB |
Output is correct |
3 |
Correct |
247 ms |
23992 KB |
Output is correct |
4 |
Correct |
682 ms |
40288 KB |
Output is correct |
5 |
Correct |
665 ms |
40388 KB |
Output is correct |
6 |
Correct |
166 ms |
19068 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
7380 KB |
Output is correct |
2 |
Correct |
5 ms |
7380 KB |
Output is correct |
3 |
Correct |
4 ms |
7380 KB |
Output is correct |
4 |
Correct |
4 ms |
7380 KB |
Output is correct |
5 |
Correct |
3 ms |
7380 KB |
Output is correct |
6 |
Incorrect |
3 ms |
7380 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
7380 KB |
Output is correct |
2 |
Correct |
5 ms |
7380 KB |
Output is correct |
3 |
Correct |
4 ms |
7380 KB |
Output is correct |
4 |
Correct |
4 ms |
7380 KB |
Output is correct |
5 |
Correct |
3 ms |
7380 KB |
Output is correct |
6 |
Incorrect |
3 ms |
7380 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |