// scanf/printf.
#ifndef LOCAL
#define NDEBUG 1
#endif
#include<bits/stdc++.h>
#pragma GCC optimize("O3")
auto const callRange=[](auto& object, int first, int last, auto function){
auto iterator=object.lower_bound(first);
while(iterator!=object.end() and iterator->first<last){
function(iterator->second);
++iterator;
}
};
int main(){
using Index=int; // for circles
struct Circle{
int x, y, r;
bool intersect(Circle other) const{
assert(r>0); assert(other.r>0);
return int64_t(x-other.x)*(x-other.x)+int64_t(y-other.y)*(y-other.y)<=
int64_t(r+other.r)*(r+other.r);
}
};
int number; std::scanf("%d",&number);
std::vector<Circle> circles(number);
for(auto& [x, y, r]: circles){
std::scanf("%d%d%d",&x,&y,&r);
x+=1000000000; y+=1000000000;
assert(x>=0 and y>=0);
}
struct A{
Index index; int r;
bool operator<(A other) const{
return r!=other.r ? r<other.r: index>other.index;
}
};
std::priority_queue<A> q;
for(Index index=0; index<number; ++index)
q.push({index, circles[index].r});
std::vector<int> result(number);
assert((result.assign(number, -1), true));
struct Cell{
std::vector<Index> indices;
std::array<std::array<Cell*, 3>, 3> adjacent; // the numbering scheme is obvious. Note that [1][1] is always *this.
std::array<std::array<Cell*, 2>, 2> children;
};
std::deque<Cell> grid;
grid.resize(1);
for(Index index=0; index<number; ++index)
grid[0].indices.push_back(index);
grid[0].adjacent[1][1]=&grid[0];
std::vector<Cell*> contain(number, &grid[0]);
for(int step=30; step>1;--step){
auto oldGrid=std::move(grid);
grid.clear();
// construct all cells and children link of old layer & new contain array
for(auto& cell: oldGrid){
std::array<std::array<Cell, 2>, 2> children{};
for(Index index: cell.indices){
auto const [x, y, r]=circles[index];
assert(r>0);
children[x>>step&1][y>>step&1].indices.push_back(index);
}
for(int c=0; c<2; ++c)
for(int d=0; d<2; ++d)
if(not children[c][d].indices.empty()){
grid.push_back(std::move(children[c][d]));
auto const cur=&grid.back();
cell.children[c][d]=cur;
for(Index index: cur->indices) contain[index]=cur;
}
}
// construct adjacent link of new layer
for(auto& cell: oldGrid){
std::array<std::array<Cell*, 4>, 4> data{};
for(int c=0; c<3; ++c)
for(int d=0; d<3; ++d){
Cell* cur=(c==1 and d==1 ? &cell: cell.adjacent[c][d]);
if(not cur) continue;
for(int e=0; e<2; ++e)
for(int f=0; f<2; ++f){
unsigned const g=c*2+e-1, h=d*2+f-1;
if(g<4 and h<4) data[g][h]=cur->children[e][f];
}
}
for(int e=0; e<2; ++e)
for(int f=0; f<2; ++f){
Cell* cur=cell.children[e][f];
if(not cur) continue;
for(int c=0; c<3; ++c)
for(int d=0; d<3; ++d){
cur->adjacent[c][d]=data[c+e][d+f];
}
}
}
while(true){
if(q.empty())
goto break_outer;
auto [index, r_]=q.top();
auto const cur=circles[index]; auto const [x, y, r]=cur;
if(r==0) {
q.pop();
continue;
}
assert(r==r_);
if(r<((1<<step)>>2))
break; // goto next step -- without popping from q
q.pop();
circles[index].r=0;
assert(result[index]==-1); result[index]=index;
auto const curCell=contain[index];
assert(std::any_of(begin(grid), end(grid), [&](auto const& it){ return &it==curCell; }));
assert(curCell->adjacent[1][1]==curCell);
auto const process=[&](Cell* cell){
if(not cell) return;
cell->indices.erase(std::remove_if(begin(cell->indices), end(cell->indices), [&](Index index1){
if(index1==index){
return true;
}
auto& cur1=circles[index1];
assert(cur1.r>0);
if(cur1.intersect(cur)){
assert(result[index1]==-1);
result[index1]=index;
cur1.r=0;
return true;
} else return false;
}),cell->indices.end());
};
for(int c=0; c<3; ++c)
for(int d=0; d<3; ++d)
process(curCell->adjacent[c][d]);
}
}
break_outer:
for(Index index=0; index<number; ++index){
auto const [x, y, r]=circles[index];
assert(result[index]!=-1);
assert(r==0);
}
for(auto it: result) std::printf("%d ",it+1);
std::printf("\n");
}
Compilation message
circle_selection.cpp: In function 'int main()':
circle_selection.cpp:70:24: warning: unused variable 'r' [-Wunused-variable]
auto const [x, y, r]=circles[index];
^
circle_selection.cpp:114:19: warning: unused variable 'r_' [-Wunused-variable]
auto [index, r_]=q.top();
^
circle_selection.cpp:115:54: warning: unused variable 'x' [-Wunused-variable]
auto const cur=circles[index]; auto const [x, y, r]=cur;
^
circle_selection.cpp:115:54: warning: unused variable 'y' [-Wunused-variable]
circle_selection.cpp:158:22: warning: unused variable 'x' [-Wunused-variable]
auto const [x, y, r]=circles[index];
^
circle_selection.cpp:158:22: warning: unused variable 'y' [-Wunused-variable]
circle_selection.cpp:158:22: warning: unused variable 'r' [-Wunused-variable]
circle_selection.cpp:27:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
int number; std::scanf("%d",&number);
~~~~~~~~~~^~~~~~~~~~~~~~
circle_selection.cpp:30:13: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
std::scanf("%d%d%d",&x,&y,&r);
~~~~~~~~~~^~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
0 ms |
256 KB |
Output is correct |
4 |
Correct |
0 ms |
256 KB |
Output is correct |
5 |
Correct |
1 ms |
256 KB |
Output is correct |
6 |
Correct |
1 ms |
512 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
256 KB |
Output is correct |
9 |
Correct |
1 ms |
256 KB |
Output is correct |
10 |
Correct |
1 ms |
256 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
1 ms |
384 KB |
Output is correct |
17 |
Correct |
2 ms |
512 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
4 ms |
768 KB |
Output is correct |
20 |
Correct |
4 ms |
768 KB |
Output is correct |
21 |
Correct |
4 ms |
760 KB |
Output is correct |
22 |
Correct |
14 ms |
2304 KB |
Output is correct |
23 |
Correct |
14 ms |
2176 KB |
Output is correct |
24 |
Correct |
15 ms |
2304 KB |
Output is correct |
25 |
Correct |
17 ms |
2176 KB |
Output is correct |
26 |
Correct |
14 ms |
2304 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
239 ms |
15020 KB |
Output is correct |
2 |
Correct |
266 ms |
14820 KB |
Output is correct |
3 |
Correct |
245 ms |
18656 KB |
Output is correct |
4 |
Correct |
271 ms |
15332 KB |
Output is correct |
5 |
Correct |
436 ms |
16932 KB |
Output is correct |
6 |
Correct |
572 ms |
30180 KB |
Output is correct |
7 |
Correct |
417 ms |
17780 KB |
Output is correct |
8 |
Correct |
472 ms |
18556 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
325 ms |
36204 KB |
Output is correct |
3 |
Correct |
1255 ms |
108768 KB |
Output is correct |
4 |
Correct |
1219 ms |
108260 KB |
Output is correct |
5 |
Correct |
880 ms |
74224 KB |
Output is correct |
6 |
Correct |
378 ms |
36840 KB |
Output is correct |
7 |
Correct |
186 ms |
20844 KB |
Output is correct |
8 |
Correct |
37 ms |
4848 KB |
Output is correct |
9 |
Correct |
1042 ms |
99484 KB |
Output is correct |
10 |
Correct |
788 ms |
62180 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1190 ms |
111768 KB |
Output is correct |
2 |
Correct |
2366 ms |
111616 KB |
Output is correct |
3 |
Correct |
341 ms |
18272 KB |
Output is correct |
4 |
Correct |
1554 ms |
111264 KB |
Output is correct |
5 |
Correct |
1559 ms |
111248 KB |
Output is correct |
6 |
Correct |
310 ms |
15820 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
0 ms |
256 KB |
Output is correct |
4 |
Correct |
0 ms |
256 KB |
Output is correct |
5 |
Correct |
1 ms |
256 KB |
Output is correct |
6 |
Correct |
1 ms |
512 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
256 KB |
Output is correct |
9 |
Correct |
1 ms |
256 KB |
Output is correct |
10 |
Correct |
1 ms |
256 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
1 ms |
384 KB |
Output is correct |
17 |
Correct |
2 ms |
512 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
4 ms |
768 KB |
Output is correct |
20 |
Correct |
4 ms |
768 KB |
Output is correct |
21 |
Correct |
4 ms |
760 KB |
Output is correct |
22 |
Correct |
14 ms |
2304 KB |
Output is correct |
23 |
Correct |
14 ms |
2176 KB |
Output is correct |
24 |
Correct |
15 ms |
2304 KB |
Output is correct |
25 |
Correct |
17 ms |
2176 KB |
Output is correct |
26 |
Correct |
14 ms |
2304 KB |
Output is correct |
27 |
Correct |
8 ms |
1152 KB |
Output is correct |
28 |
Correct |
8 ms |
1152 KB |
Output is correct |
29 |
Correct |
8 ms |
1152 KB |
Output is correct |
30 |
Correct |
34 ms |
4216 KB |
Output is correct |
31 |
Correct |
27 ms |
4224 KB |
Output is correct |
32 |
Correct |
28 ms |
4216 KB |
Output is correct |
33 |
Correct |
80 ms |
7268 KB |
Output is correct |
34 |
Correct |
85 ms |
7284 KB |
Output is correct |
35 |
Correct |
83 ms |
6636 KB |
Output is correct |
36 |
Correct |
371 ms |
37724 KB |
Output is correct |
37 |
Correct |
402 ms |
38152 KB |
Output is correct |
38 |
Correct |
321 ms |
37840 KB |
Output is correct |
39 |
Correct |
152 ms |
9572 KB |
Output is correct |
40 |
Correct |
154 ms |
9556 KB |
Output is correct |
41 |
Correct |
152 ms |
9552 KB |
Output is correct |
42 |
Correct |
110 ms |
9068 KB |
Output is correct |
43 |
Correct |
267 ms |
36204 KB |
Output is correct |
44 |
Correct |
261 ms |
36204 KB |
Output is correct |
45 |
Correct |
266 ms |
36204 KB |
Output is correct |
46 |
Correct |
254 ms |
36204 KB |
Output is correct |
47 |
Correct |
257 ms |
36204 KB |
Output is correct |
48 |
Correct |
264 ms |
36204 KB |
Output is correct |
49 |
Correct |
263 ms |
36204 KB |
Output is correct |
50 |
Correct |
272 ms |
36236 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
0 ms |
256 KB |
Output is correct |
4 |
Correct |
0 ms |
256 KB |
Output is correct |
5 |
Correct |
1 ms |
256 KB |
Output is correct |
6 |
Correct |
1 ms |
512 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
256 KB |
Output is correct |
9 |
Correct |
1 ms |
256 KB |
Output is correct |
10 |
Correct |
1 ms |
256 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
1 ms |
384 KB |
Output is correct |
17 |
Correct |
2 ms |
512 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
4 ms |
768 KB |
Output is correct |
20 |
Correct |
4 ms |
768 KB |
Output is correct |
21 |
Correct |
4 ms |
760 KB |
Output is correct |
22 |
Correct |
14 ms |
2304 KB |
Output is correct |
23 |
Correct |
14 ms |
2176 KB |
Output is correct |
24 |
Correct |
15 ms |
2304 KB |
Output is correct |
25 |
Correct |
17 ms |
2176 KB |
Output is correct |
26 |
Correct |
14 ms |
2304 KB |
Output is correct |
27 |
Correct |
239 ms |
15020 KB |
Output is correct |
28 |
Correct |
266 ms |
14820 KB |
Output is correct |
29 |
Correct |
245 ms |
18656 KB |
Output is correct |
30 |
Correct |
271 ms |
15332 KB |
Output is correct |
31 |
Correct |
436 ms |
16932 KB |
Output is correct |
32 |
Correct |
572 ms |
30180 KB |
Output is correct |
33 |
Correct |
417 ms |
17780 KB |
Output is correct |
34 |
Correct |
472 ms |
18556 KB |
Output is correct |
35 |
Correct |
0 ms |
256 KB |
Output is correct |
36 |
Correct |
325 ms |
36204 KB |
Output is correct |
37 |
Correct |
1255 ms |
108768 KB |
Output is correct |
38 |
Correct |
1219 ms |
108260 KB |
Output is correct |
39 |
Correct |
880 ms |
74224 KB |
Output is correct |
40 |
Correct |
378 ms |
36840 KB |
Output is correct |
41 |
Correct |
186 ms |
20844 KB |
Output is correct |
42 |
Correct |
37 ms |
4848 KB |
Output is correct |
43 |
Correct |
1042 ms |
99484 KB |
Output is correct |
44 |
Correct |
788 ms |
62180 KB |
Output is correct |
45 |
Correct |
1190 ms |
111768 KB |
Output is correct |
46 |
Correct |
2366 ms |
111616 KB |
Output is correct |
47 |
Correct |
341 ms |
18272 KB |
Output is correct |
48 |
Correct |
1554 ms |
111264 KB |
Output is correct |
49 |
Correct |
1559 ms |
111248 KB |
Output is correct |
50 |
Correct |
310 ms |
15820 KB |
Output is correct |
51 |
Correct |
8 ms |
1152 KB |
Output is correct |
52 |
Correct |
8 ms |
1152 KB |
Output is correct |
53 |
Correct |
8 ms |
1152 KB |
Output is correct |
54 |
Correct |
34 ms |
4216 KB |
Output is correct |
55 |
Correct |
27 ms |
4224 KB |
Output is correct |
56 |
Correct |
28 ms |
4216 KB |
Output is correct |
57 |
Correct |
80 ms |
7268 KB |
Output is correct |
58 |
Correct |
85 ms |
7284 KB |
Output is correct |
59 |
Correct |
83 ms |
6636 KB |
Output is correct |
60 |
Correct |
371 ms |
37724 KB |
Output is correct |
61 |
Correct |
402 ms |
38152 KB |
Output is correct |
62 |
Correct |
321 ms |
37840 KB |
Output is correct |
63 |
Correct |
152 ms |
9572 KB |
Output is correct |
64 |
Correct |
154 ms |
9556 KB |
Output is correct |
65 |
Correct |
152 ms |
9552 KB |
Output is correct |
66 |
Correct |
110 ms |
9068 KB |
Output is correct |
67 |
Correct |
267 ms |
36204 KB |
Output is correct |
68 |
Correct |
261 ms |
36204 KB |
Output is correct |
69 |
Correct |
266 ms |
36204 KB |
Output is correct |
70 |
Correct |
254 ms |
36204 KB |
Output is correct |
71 |
Correct |
257 ms |
36204 KB |
Output is correct |
72 |
Correct |
264 ms |
36204 KB |
Output is correct |
73 |
Correct |
263 ms |
36204 KB |
Output is correct |
74 |
Correct |
272 ms |
36236 KB |
Output is correct |
75 |
Correct |
263 ms |
15712 KB |
Output is correct |
76 |
Correct |
271 ms |
15844 KB |
Output is correct |
77 |
Correct |
279 ms |
16508 KB |
Output is correct |
78 |
Correct |
252 ms |
17504 KB |
Output is correct |
79 |
Correct |
315 ms |
16228 KB |
Output is correct |
80 |
Correct |
256 ms |
17504 KB |
Output is correct |
81 |
Correct |
1236 ms |
108720 KB |
Output is correct |
82 |
Correct |
1244 ms |
108200 KB |
Output is correct |
83 |
Correct |
1203 ms |
108972 KB |
Output is correct |
84 |
Correct |
1080 ms |
106180 KB |
Output is correct |
85 |
Correct |
1246 ms |
108512 KB |
Output is correct |
86 |
Correct |
1180 ms |
108524 KB |
Output is correct |
87 |
Correct |
1040 ms |
98372 KB |
Output is correct |
88 |
Correct |
550 ms |
26436 KB |
Output is correct |
89 |
Correct |
563 ms |
26296 KB |
Output is correct |
90 |
Correct |
550 ms |
26336 KB |
Output is correct |
91 |
Correct |
555 ms |
26272 KB |
Output is correct |
92 |
Correct |
551 ms |
26336 KB |
Output is correct |
93 |
Correct |
1285 ms |
107852 KB |
Output is correct |
94 |
Correct |
1272 ms |
105952 KB |
Output is correct |
95 |
Correct |
1326 ms |
108000 KB |
Output is correct |
96 |
Correct |
1173 ms |
105332 KB |
Output is correct |
97 |
Correct |
1696 ms |
109280 KB |
Output is correct |
98 |
Correct |
674 ms |
30944 KB |
Output is correct |
99 |
Correct |
1294 ms |
107360 KB |
Output is correct |
100 |
Correct |
1580 ms |
110996 KB |
Output is correct |
101 |
Correct |
658 ms |
39644 KB |
Output is correct |
102 |
Correct |
1153 ms |
94972 KB |
Output is correct |
103 |
Correct |
1072 ms |
95060 KB |
Output is correct |
104 |
Correct |
1396 ms |
108820 KB |
Output is correct |
105 |
Correct |
435 ms |
23660 KB |
Output is correct |
106 |
Correct |
888 ms |
91488 KB |
Output is correct |
107 |
Correct |
858 ms |
91744 KB |
Output is correct |
108 |
Correct |
874 ms |
91512 KB |
Output is correct |
109 |
Correct |
934 ms |
91756 KB |
Output is correct |
110 |
Correct |
888 ms |
91584 KB |
Output is correct |
111 |
Correct |
985 ms |
91552 KB |
Output is correct |
112 |
Correct |
850 ms |
91472 KB |
Output is correct |
113 |
Correct |
856 ms |
91488 KB |
Output is correct |
114 |
Correct |
860 ms |
91448 KB |
Output is correct |
115 |
Correct |
849 ms |
91488 KB |
Output is correct |
116 |
Correct |
909 ms |
91744 KB |
Output is correct |