#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 5;
long long sqr(long long x){ return x * x; }
struct circle{
long long x, y, r;
bool intersect(circle A){
return sqr(x - A.x) + sqr(y - A.y) <= sqr(r + A.r);
}
};
int n;
circle a[N];
namespace subtask1{
int ans[N];
void solve(){
while (true){
long long maxr = 0;
int idx = 0;
for (int i = 1; i <= n; ++ i) if (!ans[i] && a[i].r > maxr){
idx = i;
maxr = a[i].r;
}
if (!idx) break;
for (int i = 1; i <= n; ++ i) if (!ans[i] && a[idx].intersect(a[i])) ans[i] = idx;
}
for (int i = 1; i <= n; ++ i) cout << ans[i] << ' ';
}
}
vector <int> sr;
namespace subtask2{
int ans[N];
set <pair <int, int>> l, r;
void solve(){
for (int i = 1; i <= n; ++ i) {
l.insert({a[i].x - a[i].r, i});
r.insert({a[i].x + a[i].r, i});
}
for (int id : sr){
if (ans[id]) continue;
int le = a[id].x - a[id].r;
int ri = a[id].x + a[id].r;
auto it = l.lower_bound({le, 0});
while (it != l.end() && it -> first <= ri){
int del = it -> second;
ans[del] = id;
++ it;
l.erase({a[del].x - a[del].r, del});
r.erase({a[del].x + a[del].r, del});
}
it = r.lower_bound({le, 0});
while (it != r.end() && it -> first <= ri){
int del = it -> second;
ans[del] = id;
++ it;
l.erase({a[del].x - a[del].r, del});
r.erase({a[del].x + a[del].r, del});
}
}
for (int i = 1; i <= n; ++ i) cout << ans[i] << ' ';
}
}
namespace subtask4{
using pii = pair <int, int>;
map <pii, set <int>> grid;
int ans[N];
void solve(){
int radius = a[1].r;
for (int i = 1; i <= n; ++ i){
int x = a[i].x / radius;
int y = a[i].y / radius;
grid[{x, y}].insert(i);
}
for (int id : sr){
if (ans[id]) continue;
int x = a[id].x / radius;
int y = a[id].y / radius;
for (int i = x - 2; i <= x + 2; ++ i){
for (int j = y - 2; j <= y + 2; ++ j){
auto it1 = grid.find({i, j});
if (it1 == grid.end()) continue;
for (auto it = (it1 -> second).begin(); it != (it1 -> second).end();){
if (a[id].intersect(a[*it])){
ans[*it] = id;
it = (it1 -> second).erase(it);
}
else ++ it;
}
}
}
}
for (int i = 1; i <= n; ++ i) cout << ans[i] << ' ';
}
}
namespace Accepted{
using pii = pair <int, int>;
int block = 0, ans[N];
set <int> remain;
map <pii, set <int>> grid;
void recalc(){
grid.clear();
for (int id : remain) {
int x = a[id].x / block;
int y = a[id].y / block;
grid[{x, y}].insert(id);
}
}
void solve(){
for (int i = 1; i <= n; ++ i) remain.insert(i);
for (int id : sr){
if (ans[id]) continue;
if (block == 0 || a[id].r * 2 <= block){
block = a[id].r;
recalc();
}
int x = a[id].x / block;
int y = a[id].y / block;
for (int i = x - 2; i <= x + 2; ++ i){
for (int j = y - 2; j <= y + 2; ++ j){
auto it1 = grid.find({i, j});
if (it1 == grid.end()) continue;
for (auto it = (it1 -> second).begin(); it != (it1 -> second).end();){
if (a[id].intersect(a[*it])){
ans[*it] = id;
remain.erase(*it);
it = (it1 -> second).erase(it);
}
else ++ it;
}
}
}
}
for (int i = 1; i <= n; ++ i) cout << ans[i] << ' ';
}
}
void solve(){
cin >> n;
bool ck2 = true;
bool ck4 = true;
for (int i = 1; i <= n; ++ i) {
sr.push_back(i);
cin >> a[i].x >> a[i].y >> a[i].r;
if (a[i].y != 0) ck2 = false;
if (i > 1 && a[i].r != a[i - 1].r) ck4 = false;
}
sort(sr.begin(), sr.end(), [&](int u, int v){
if (a[u].r == a[v].r) return u < v;
return a[u].r > a[v].r;
});
if (n <= 5000) subtask1::solve();
else if (ck2) subtask2::solve();
else if (ck4) subtask4::solve();
else Accepted::solve();
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
solve();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
0 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
2 ms |
4444 KB |
Output is correct |
12 |
Correct |
1 ms |
4444 KB |
Output is correct |
13 |
Correct |
1 ms |
4444 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
1 ms |
4444 KB |
Output is correct |
17 |
Correct |
1 ms |
4444 KB |
Output is correct |
18 |
Correct |
1 ms |
4444 KB |
Output is correct |
19 |
Correct |
2 ms |
4444 KB |
Output is correct |
20 |
Correct |
4 ms |
4604 KB |
Output is correct |
21 |
Correct |
2 ms |
4444 KB |
Output is correct |
22 |
Correct |
83 ms |
4600 KB |
Output is correct |
23 |
Correct |
75 ms |
4616 KB |
Output is correct |
24 |
Correct |
78 ms |
4600 KB |
Output is correct |
25 |
Correct |
82 ms |
4596 KB |
Output is correct |
26 |
Correct |
81 ms |
4604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
567 ms |
41376 KB |
Output is correct |
2 |
Correct |
597 ms |
41216 KB |
Output is correct |
3 |
Correct |
559 ms |
41128 KB |
Output is correct |
4 |
Correct |
568 ms |
42168 KB |
Output is correct |
5 |
Correct |
503 ms |
41184 KB |
Output is correct |
6 |
Correct |
490 ms |
41312 KB |
Output is correct |
7 |
Correct |
442 ms |
41240 KB |
Output is correct |
8 |
Correct |
441 ms |
41160 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
416 ms |
26716 KB |
Output is correct |
3 |
Correct |
1834 ms |
78596 KB |
Output is correct |
4 |
Correct |
1898 ms |
78600 KB |
Output is correct |
5 |
Correct |
1780 ms |
72256 KB |
Output is correct |
6 |
Correct |
552 ms |
38532 KB |
Output is correct |
7 |
Correct |
204 ms |
23508 KB |
Output is correct |
8 |
Correct |
29 ms |
8064 KB |
Output is correct |
9 |
Correct |
1975 ms |
78024 KB |
Output is correct |
10 |
Correct |
1323 ms |
71820 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
995 ms |
56264 KB |
Output is correct |
2 |
Correct |
746 ms |
56492 KB |
Output is correct |
3 |
Correct |
343 ms |
35780 KB |
Output is correct |
4 |
Correct |
803 ms |
56376 KB |
Output is correct |
5 |
Correct |
807 ms |
56236 KB |
Output is correct |
6 |
Correct |
243 ms |
29128 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
0 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
2 ms |
4444 KB |
Output is correct |
12 |
Correct |
1 ms |
4444 KB |
Output is correct |
13 |
Correct |
1 ms |
4444 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
1 ms |
4444 KB |
Output is correct |
17 |
Correct |
1 ms |
4444 KB |
Output is correct |
18 |
Correct |
1 ms |
4444 KB |
Output is correct |
19 |
Correct |
2 ms |
4444 KB |
Output is correct |
20 |
Correct |
4 ms |
4604 KB |
Output is correct |
21 |
Correct |
2 ms |
4444 KB |
Output is correct |
22 |
Correct |
83 ms |
4600 KB |
Output is correct |
23 |
Correct |
75 ms |
4616 KB |
Output is correct |
24 |
Correct |
78 ms |
4600 KB |
Output is correct |
25 |
Correct |
82 ms |
4596 KB |
Output is correct |
26 |
Correct |
81 ms |
4604 KB |
Output is correct |
27 |
Correct |
7 ms |
5468 KB |
Output is correct |
28 |
Correct |
7 ms |
5724 KB |
Output is correct |
29 |
Correct |
7 ms |
5708 KB |
Output is correct |
30 |
Correct |
26 ms |
6748 KB |
Output is correct |
31 |
Correct |
25 ms |
6792 KB |
Output is correct |
32 |
Correct |
33 ms |
6748 KB |
Output is correct |
33 |
Correct |
70 ms |
20436 KB |
Output is correct |
34 |
Correct |
73 ms |
20476 KB |
Output is correct |
35 |
Correct |
81 ms |
20180 KB |
Output is correct |
36 |
Correct |
363 ms |
29140 KB |
Output is correct |
37 |
Correct |
357 ms |
29184 KB |
Output is correct |
38 |
Correct |
347 ms |
29288 KB |
Output is correct |
39 |
Correct |
478 ms |
26360 KB |
Output is correct |
40 |
Correct |
498 ms |
26324 KB |
Output is correct |
41 |
Correct |
476 ms |
26320 KB |
Output is correct |
42 |
Correct |
145 ms |
23392 KB |
Output is correct |
43 |
Correct |
205 ms |
24424 KB |
Output is correct |
44 |
Correct |
213 ms |
24412 KB |
Output is correct |
45 |
Correct |
204 ms |
24396 KB |
Output is correct |
46 |
Correct |
206 ms |
24276 KB |
Output is correct |
47 |
Correct |
198 ms |
24464 KB |
Output is correct |
48 |
Correct |
207 ms |
24264 KB |
Output is correct |
49 |
Correct |
209 ms |
24392 KB |
Output is correct |
50 |
Correct |
195 ms |
24272 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
0 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
2 ms |
4444 KB |
Output is correct |
12 |
Correct |
1 ms |
4444 KB |
Output is correct |
13 |
Correct |
1 ms |
4444 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
1 ms |
4444 KB |
Output is correct |
17 |
Correct |
1 ms |
4444 KB |
Output is correct |
18 |
Correct |
1 ms |
4444 KB |
Output is correct |
19 |
Correct |
2 ms |
4444 KB |
Output is correct |
20 |
Correct |
4 ms |
4604 KB |
Output is correct |
21 |
Correct |
2 ms |
4444 KB |
Output is correct |
22 |
Correct |
83 ms |
4600 KB |
Output is correct |
23 |
Correct |
75 ms |
4616 KB |
Output is correct |
24 |
Correct |
78 ms |
4600 KB |
Output is correct |
25 |
Correct |
82 ms |
4596 KB |
Output is correct |
26 |
Correct |
81 ms |
4604 KB |
Output is correct |
27 |
Correct |
567 ms |
41376 KB |
Output is correct |
28 |
Correct |
597 ms |
41216 KB |
Output is correct |
29 |
Correct |
559 ms |
41128 KB |
Output is correct |
30 |
Correct |
568 ms |
42168 KB |
Output is correct |
31 |
Correct |
503 ms |
41184 KB |
Output is correct |
32 |
Correct |
490 ms |
41312 KB |
Output is correct |
33 |
Correct |
442 ms |
41240 KB |
Output is correct |
34 |
Correct |
441 ms |
41160 KB |
Output is correct |
35 |
Correct |
1 ms |
4444 KB |
Output is correct |
36 |
Correct |
416 ms |
26716 KB |
Output is correct |
37 |
Correct |
1834 ms |
78596 KB |
Output is correct |
38 |
Correct |
1898 ms |
78600 KB |
Output is correct |
39 |
Correct |
1780 ms |
72256 KB |
Output is correct |
40 |
Correct |
552 ms |
38532 KB |
Output is correct |
41 |
Correct |
204 ms |
23508 KB |
Output is correct |
42 |
Correct |
29 ms |
8064 KB |
Output is correct |
43 |
Correct |
1975 ms |
78024 KB |
Output is correct |
44 |
Correct |
1323 ms |
71820 KB |
Output is correct |
45 |
Correct |
995 ms |
56264 KB |
Output is correct |
46 |
Correct |
746 ms |
56492 KB |
Output is correct |
47 |
Correct |
343 ms |
35780 KB |
Output is correct |
48 |
Correct |
803 ms |
56376 KB |
Output is correct |
49 |
Correct |
807 ms |
56236 KB |
Output is correct |
50 |
Correct |
243 ms |
29128 KB |
Output is correct |
51 |
Correct |
7 ms |
5468 KB |
Output is correct |
52 |
Correct |
7 ms |
5724 KB |
Output is correct |
53 |
Correct |
7 ms |
5708 KB |
Output is correct |
54 |
Correct |
26 ms |
6748 KB |
Output is correct |
55 |
Correct |
25 ms |
6792 KB |
Output is correct |
56 |
Correct |
33 ms |
6748 KB |
Output is correct |
57 |
Correct |
70 ms |
20436 KB |
Output is correct |
58 |
Correct |
73 ms |
20476 KB |
Output is correct |
59 |
Correct |
81 ms |
20180 KB |
Output is correct |
60 |
Correct |
363 ms |
29140 KB |
Output is correct |
61 |
Correct |
357 ms |
29184 KB |
Output is correct |
62 |
Correct |
347 ms |
29288 KB |
Output is correct |
63 |
Correct |
478 ms |
26360 KB |
Output is correct |
64 |
Correct |
498 ms |
26324 KB |
Output is correct |
65 |
Correct |
476 ms |
26320 KB |
Output is correct |
66 |
Correct |
145 ms |
23392 KB |
Output is correct |
67 |
Correct |
205 ms |
24424 KB |
Output is correct |
68 |
Correct |
213 ms |
24412 KB |
Output is correct |
69 |
Correct |
204 ms |
24396 KB |
Output is correct |
70 |
Correct |
206 ms |
24276 KB |
Output is correct |
71 |
Correct |
198 ms |
24464 KB |
Output is correct |
72 |
Correct |
207 ms |
24264 KB |
Output is correct |
73 |
Correct |
209 ms |
24392 KB |
Output is correct |
74 |
Correct |
195 ms |
24272 KB |
Output is correct |
75 |
Correct |
273 ms |
51712 KB |
Output is correct |
76 |
Correct |
278 ms |
51140 KB |
Output is correct |
77 |
Correct |
237 ms |
51436 KB |
Output is correct |
78 |
Correct |
245 ms |
51144 KB |
Output is correct |
79 |
Correct |
450 ms |
51176 KB |
Output is correct |
80 |
Correct |
241 ms |
51144 KB |
Output is correct |
81 |
Correct |
1658 ms |
78544 KB |
Output is correct |
82 |
Correct |
1586 ms |
78372 KB |
Output is correct |
83 |
Correct |
1511 ms |
78312 KB |
Output is correct |
84 |
Correct |
1617 ms |
78792 KB |
Output is correct |
85 |
Correct |
1595 ms |
78536 KB |
Output is correct |
86 |
Correct |
1558 ms |
78536 KB |
Output is correct |
87 |
Correct |
1761 ms |
78376 KB |
Output is correct |
88 |
Correct |
1970 ms |
69592 KB |
Output is correct |
89 |
Correct |
1949 ms |
69596 KB |
Output is correct |
90 |
Correct |
1978 ms |
69800 KB |
Output is correct |
91 |
Correct |
1793 ms |
69572 KB |
Output is correct |
92 |
Correct |
1889 ms |
69788 KB |
Output is correct |
93 |
Correct |
1204 ms |
77408 KB |
Output is correct |
94 |
Correct |
1221 ms |
77764 KB |
Output is correct |
95 |
Correct |
1130 ms |
77344 KB |
Output is correct |
96 |
Correct |
1207 ms |
77412 KB |
Output is correct |
97 |
Correct |
1629 ms |
77512 KB |
Output is correct |
98 |
Correct |
846 ms |
67492 KB |
Output is correct |
99 |
Correct |
1143 ms |
77568 KB |
Output is correct |
100 |
Correct |
1080 ms |
77320 KB |
Output is correct |
101 |
Correct |
1097 ms |
71836 KB |
Output is correct |
102 |
Correct |
1122 ms |
77000 KB |
Output is correct |
103 |
Correct |
1499 ms |
77256 KB |
Output is correct |
104 |
Correct |
1144 ms |
77460 KB |
Output is correct |
105 |
Correct |
574 ms |
60868 KB |
Output is correct |
106 |
Correct |
656 ms |
62144 KB |
Output is correct |
107 |
Correct |
654 ms |
62152 KB |
Output is correct |
108 |
Correct |
695 ms |
62148 KB |
Output is correct |
109 |
Correct |
745 ms |
62172 KB |
Output is correct |
110 |
Correct |
684 ms |
62184 KB |
Output is correct |
111 |
Correct |
701 ms |
62116 KB |
Output is correct |
112 |
Correct |
723 ms |
62184 KB |
Output is correct |
113 |
Correct |
702 ms |
62216 KB |
Output is correct |
114 |
Correct |
720 ms |
62152 KB |
Output is correct |
115 |
Correct |
673 ms |
62152 KB |
Output is correct |
116 |
Correct |
633 ms |
62148 KB |
Output is correct |