#include<iostream>
#include<algorithm>
#include<set>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define ff first
#define ss second
const int N = 3e5 + 7;
int n;
int ans[N];
struct Data {
int x, y, r, id;
Data() {}
bool operator < (const Data &o) const {
if (r != o.r) return r > o.r;
return id < o.id;
}
} a[N];
namespace subtask1 {
#define sqr(x) (ll)(x) * (x)
bool check(const Data &a, const Data &b) {
return sqr(a.r + b.r) >= sqr(a.x - b.x) + sqr(a.y - b.y);
}
#undef sqr
void solve() {
for (int i = 1; i <= n; ++i) if (!ans[a[i].id]) {
ans[a[i].id] = a[i].id;
for (int j = i + 1; j <= n; ++j)
if (!ans[a[j].id] && check(a[i], a[j])) ans[a[j].id] = a[i].id;
}
}
}
namespace subtask2 {
set<pii> s[2];
void init() {
for (int i = 1; i <= n; ++i) {
s[0].emplace(a[i].x - a[i].r, i);
s[1].emplace(a[i].x + a[i].r, i);
}
}
void del(int i, int x) {
ans[a[i].id] = x;
s[0].erase(pii(a[i].x - a[i].r, i));
s[1].erase(pii(a[i].x + a[i].r, i));
}
void solve() {
init();
for (int i = 1, j; i <= n; ++i) if (!ans[a[i].id]) {
del(i, a[i].id);
for (int b = 0; b < 2; ++b) {
set<pii>::iterator it = s[b].lower_bound(pii(a[i].x, 0)), it2;
while (it != s[b].end() && it->ff <= a[i].x + a[i].r) {
j = it->ss, ++it;
del(j, a[i].id);
}
it = s[b].lower_bound(pii(a[i].x, 0));
if (it != s[b].begin()) {
--it;
while (it->ff >= a[i].x - a[i].r) {
j = it->ss;
bool stop = it == s[b].begin() ? true : (--it, false);
del(j, a[i].id);
if (stop) break;
}
}
}
}
}
}
int main() {
cin.tie(NULL)->sync_with_stdio(false);
cin >> n;
for (int i = 1; i <= n; ++i)
cin >> a[i].x >> a[i].y >> a[i].r, a[i].id = i;
sort(a + 1, a + n + 1);
if (n <= 5000)
subtask1::solve();
else
subtask2::solve();
for (int i = 1; i <= n; ++i) cout << ans[i] << ' ';
}
/** /\_/\
* (= ._.)
* / >0 \>1
**/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
2 ms |
340 KB |
Output is correct |
20 |
Correct |
2 ms |
340 KB |
Output is correct |
21 |
Correct |
3 ms |
340 KB |
Output is correct |
22 |
Correct |
29 ms |
340 KB |
Output is correct |
23 |
Correct |
29 ms |
408 KB |
Output is correct |
24 |
Correct |
32 ms |
408 KB |
Output is correct |
25 |
Correct |
27 ms |
408 KB |
Output is correct |
26 |
Correct |
26 ms |
428 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
813 ms |
36372 KB |
Output is correct |
2 |
Correct |
798 ms |
36492 KB |
Output is correct |
3 |
Correct |
782 ms |
36184 KB |
Output is correct |
4 |
Correct |
797 ms |
36436 KB |
Output is correct |
5 |
Correct |
623 ms |
36256 KB |
Output is correct |
6 |
Correct |
677 ms |
40944 KB |
Output is correct |
7 |
Correct |
611 ms |
41060 KB |
Output is correct |
8 |
Correct |
569 ms |
40948 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
141 ms |
12188 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
560 ms |
35992 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
2 ms |
340 KB |
Output is correct |
20 |
Correct |
2 ms |
340 KB |
Output is correct |
21 |
Correct |
3 ms |
340 KB |
Output is correct |
22 |
Correct |
29 ms |
340 KB |
Output is correct |
23 |
Correct |
29 ms |
408 KB |
Output is correct |
24 |
Correct |
32 ms |
408 KB |
Output is correct |
25 |
Correct |
27 ms |
408 KB |
Output is correct |
26 |
Correct |
26 ms |
428 KB |
Output is correct |
27 |
Incorrect |
10 ms |
1492 KB |
Output isn't correct |
28 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
2 ms |
340 KB |
Output is correct |
20 |
Correct |
2 ms |
340 KB |
Output is correct |
21 |
Correct |
3 ms |
340 KB |
Output is correct |
22 |
Correct |
29 ms |
340 KB |
Output is correct |
23 |
Correct |
29 ms |
408 KB |
Output is correct |
24 |
Correct |
32 ms |
408 KB |
Output is correct |
25 |
Correct |
27 ms |
408 KB |
Output is correct |
26 |
Correct |
26 ms |
428 KB |
Output is correct |
27 |
Correct |
813 ms |
36372 KB |
Output is correct |
28 |
Correct |
798 ms |
36492 KB |
Output is correct |
29 |
Correct |
782 ms |
36184 KB |
Output is correct |
30 |
Correct |
797 ms |
36436 KB |
Output is correct |
31 |
Correct |
623 ms |
36256 KB |
Output is correct |
32 |
Correct |
677 ms |
40944 KB |
Output is correct |
33 |
Correct |
611 ms |
41060 KB |
Output is correct |
34 |
Correct |
569 ms |
40948 KB |
Output is correct |
35 |
Correct |
0 ms |
212 KB |
Output is correct |
36 |
Incorrect |
141 ms |
12188 KB |
Output isn't correct |
37 |
Halted |
0 ms |
0 KB |
- |