#pragma GCC optimize("O3,inline")
#include <bits/stdc++.h>
using namespace std;
using namespace std::chrono;
using ll = long long;
const ll MOD = 1e9+7;
const int MAX_N = 3e5+5;
int n;
struct Node
{
ll x, y, r;
int p;
bool visited;
} A[MAX_N];
struct LLNode
{
int idx;
LLNode* next = nullptr;
inline LLNode()
{
}
inline LLNode(int val)
: idx(val)
{
}
} LLNodes[MAX_N];
int llcounter = 0;
inline LLNode* getLLNode()
{
return &LLNodes[llcounter++];
}
int dup;
struct Quad
{
ll l, r, bot, top;
array<Quad*, 4> childs = {};
LLNode* llnode = nullptr;
int sz;
inline Quad()
{
}
inline Quad(const ll & _l, const ll & _r, const ll & _bot, const ll & _top)
: l(_l), r(_r), bot(_bot), top(_top)
{
sz = 0;
}
void add(const ll & x, const ll & y, const int & idx)
{
if(x < l || x > r || y < bot || y > top) {
return;
}
sz++;
// cerr << "l = " << l << ", r = " << r << ", "
// << "bot = " << bot << ", top = " << top << "\n";
if(l == r && bot == top) {
if(llnode == nullptr) {
llnode = getLLNode();
llnode->idx = idx;
}
else {
dup++;
LLNode* temp = getLLNode();
temp->idx = idx;
temp->next = llnode;
llnode = temp;
}
}
else {
ll midH, midV;
midH = l+(r-l)/2;
midV = bot+(top-bot)/2;
if(l != r && top != bot) {
if(childs[0] == nullptr && !(x < l || x > midH || y < bot || y > midV)) {
childs[0] = new Quad(l, midH, bot, midV);
}
else if(childs[1] == nullptr && !(x < midH+1 || x > r || y < bot || y > midV)) {
childs[1] = new Quad(midH+1, r, bot, midV);
}
else if(childs[2] == nullptr && !(x < l || x > midH || y < midV+1 || y > top)) {
childs[2] = new Quad(l, midH, midV+1, top);
}
else if(childs[3] == nullptr && !(x < midH+1 || x > r || y < midV+1 || y > top)) {
childs[3] = new Quad(midH+1, r, midV+1, top);
}
}
else if(l != r) {
if(childs[0] == nullptr && !(x < l || x > midH || y < bot || y > top)) {
childs[0] = new Quad(l, midH, bot, midV);
}
else if(childs[1] == nullptr && !(x < midH+1 || x > r || y < bot || y > top)) {
childs[1] = new Quad(midH+1, r, bot, top);
}
}
else if(top != bot) {
if(childs[0] == nullptr && !(x < l || x > r || y < bot || y > midV)) {
childs[0] = new Quad(l, r, bot, midV);
}
else if(childs[1] == nullptr && !(x < l || x > r || y < midV+1 || y > top)) {
childs[1] = new Quad(l, r, midV+1, top);
}
}
for(int k = 0; k < 4; k++) {
if(childs[k] != nullptr) {
childs[k]->add(x, y, idx);
}
}
}
}
void setInRange(const ll & x, const ll & y, const ll & radius, const int & idx)
{
if(x+2*radius < l || x-2*radius > r || y+2*radius < bot || y-2*radius > top || sz == 0) {
return;
}
// cerr << "l = " << l << ", r = " << r << ", "
// << "bot = " << bot << ", top = " << top << "\n";
if(l == r && bot == top) {
while(llnode != nullptr &&
(A[idx].r+A[llnode->idx].r)*(A[idx].r+A[llnode->idx].r)
>= llabs(A[idx].x-A[llnode->idx].x)*llabs(A[idx].x-A[llnode->idx].x)
+llabs(A[idx].y-A[llnode->idx].y)*llabs(A[idx].y-A[llnode->idx].y)) {
A[llnode->idx].p = idx;
A[llnode->idx].visited = true;
sz--;
llnode = llnode->next;
}
return;
}
int cnt = 0;
for(int k = 0; k < 4; k++) {
if(childs[k] != nullptr) {
childs[k]->setInRange(x, y, radius, idx);
cnt += childs[k]->sz;
}
}
sz = cnt;
}
};
Quad Q(-1000000000, 1000000000, -1000000000, 1000000000);
inline int nextInt()
{
int c = getchar();
while (c != '-' && (c < '0' || c > '9')) {
c = getchar();
}
int x = 0;
bool neg = false;
if (c == '-') {
neg = true;
c = getchar();
}
while (c >= '0' && c <= '9') {
x = x*10+(c-'0');
c = getchar();
}
if (neg)
return -x;
return x;
}
int main()
{
auto stop = steady_clock::now();
n = nextInt();
for(int i = 0; i < n; i++) {
A[i].x = nextInt();
A[i].y = nextInt();
A[i].r = nextInt();
}
// cerr << "Exec: " << duration_cast<milliseconds>(steady_clock::now()-stop).count() << " ms\n";
vector<int> I(n);
iota(I.begin(), I.end(), 0);
sort(I.begin(), I.end(),
[&](int a, int b)
{
return A[a].r > A[b].r || (A[a].r == A[b].r && a < b);
});
for(int i = n-1; i >= 0; i--) {
int idx = I[i];
//cerr << i << " started\n";
Q.add(A[idx].x, A[idx].y, idx);
//cerr << i << " finished\n";
}
for(int i = 0; i < n; i++) {
int idx = I[i];
if(A[idx].visited) continue;
Q.setInRange(A[idx].x, A[idx].y, A[idx].r, idx);
}
for(int i = 0; i < n; i++) {
cout << 1+A[i].p << " ";
}
cout << "\n";
// cerr << "Dupe: " << dup << "\n";
// cerr << "Exec: " << duration_cast<milliseconds>(steady_clock::now()-stop).count() << " ms\n";
return 0;
}
/*
11
9 9 2
13 2 1
11 8 2
3 3 2
3 12 1
12 14 1
9 8 5
2 8 2
5 2 1
14 4 2
14 14 1
*/
Compilation message
circle_selection.cpp: In function 'int main()':
circle_selection.cpp:183:10: warning: variable 'stop' set but not used [-Wunused-but-set-variable]
183 | auto stop = steady_clock::now();
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4940 KB |
Output is correct |
2 |
Correct |
2 ms |
4940 KB |
Output is correct |
3 |
Correct |
3 ms |
4940 KB |
Output is correct |
4 |
Correct |
2 ms |
4940 KB |
Output is correct |
5 |
Correct |
2 ms |
4896 KB |
Output is correct |
6 |
Correct |
3 ms |
5196 KB |
Output is correct |
7 |
Correct |
3 ms |
5196 KB |
Output is correct |
8 |
Correct |
3 ms |
5132 KB |
Output is correct |
9 |
Correct |
3 ms |
5196 KB |
Output is correct |
10 |
Correct |
3 ms |
5196 KB |
Output is correct |
11 |
Correct |
3 ms |
5196 KB |
Output is correct |
12 |
Correct |
3 ms |
5196 KB |
Output is correct |
13 |
Correct |
3 ms |
5196 KB |
Output is correct |
14 |
Correct |
3 ms |
5196 KB |
Output is correct |
15 |
Correct |
3 ms |
5196 KB |
Output is correct |
16 |
Correct |
6 ms |
7372 KB |
Output is correct |
17 |
Correct |
6 ms |
7116 KB |
Output is correct |
18 |
Correct |
5 ms |
7116 KB |
Output is correct |
19 |
Correct |
18 ms |
15600 KB |
Output is correct |
20 |
Correct |
16 ms |
13260 KB |
Output is correct |
21 |
Correct |
20 ms |
16396 KB |
Output is correct |
22 |
Correct |
20 ms |
15588 KB |
Output is correct |
23 |
Correct |
21 ms |
14712 KB |
Output is correct |
24 |
Correct |
21 ms |
15820 KB |
Output is correct |
25 |
Correct |
21 ms |
16584 KB |
Output is correct |
26 |
Correct |
21 ms |
16264 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
946 ms |
359824 KB |
Output is correct |
2 |
Correct |
982 ms |
371516 KB |
Output is correct |
3 |
Correct |
954 ms |
350636 KB |
Output is correct |
4 |
Correct |
1004 ms |
388056 KB |
Output is correct |
5 |
Correct |
533 ms |
66228 KB |
Output is correct |
6 |
Correct |
882 ms |
212092 KB |
Output is correct |
7 |
Correct |
667 ms |
135984 KB |
Output is correct |
8 |
Correct |
725 ms |
158276 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4940 KB |
Output is correct |
2 |
Correct |
494 ms |
229708 KB |
Output is correct |
3 |
Correct |
1634 ms |
657212 KB |
Output is correct |
4 |
Correct |
1611 ms |
657248 KB |
Output is correct |
5 |
Correct |
1495 ms |
588348 KB |
Output is correct |
6 |
Correct |
693 ms |
319772 KB |
Output is correct |
7 |
Correct |
356 ms |
170208 KB |
Output is correct |
8 |
Correct |
64 ms |
38528 KB |
Output is correct |
9 |
Correct |
1588 ms |
595984 KB |
Output is correct |
10 |
Correct |
1424 ms |
616636 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1461 ms |
601944 KB |
Output is correct |
2 |
Correct |
1380 ms |
574832 KB |
Output is correct |
3 |
Correct |
1266 ms |
602308 KB |
Output is correct |
4 |
Correct |
1447 ms |
621044 KB |
Output is correct |
5 |
Correct |
1404 ms |
599304 KB |
Output is correct |
6 |
Correct |
1216 ms |
591656 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4940 KB |
Output is correct |
2 |
Correct |
2 ms |
4940 KB |
Output is correct |
3 |
Correct |
3 ms |
4940 KB |
Output is correct |
4 |
Correct |
2 ms |
4940 KB |
Output is correct |
5 |
Correct |
2 ms |
4896 KB |
Output is correct |
6 |
Correct |
3 ms |
5196 KB |
Output is correct |
7 |
Correct |
3 ms |
5196 KB |
Output is correct |
8 |
Correct |
3 ms |
5132 KB |
Output is correct |
9 |
Correct |
3 ms |
5196 KB |
Output is correct |
10 |
Correct |
3 ms |
5196 KB |
Output is correct |
11 |
Correct |
3 ms |
5196 KB |
Output is correct |
12 |
Correct |
3 ms |
5196 KB |
Output is correct |
13 |
Correct |
3 ms |
5196 KB |
Output is correct |
14 |
Correct |
3 ms |
5196 KB |
Output is correct |
15 |
Correct |
3 ms |
5196 KB |
Output is correct |
16 |
Correct |
6 ms |
7372 KB |
Output is correct |
17 |
Correct |
6 ms |
7116 KB |
Output is correct |
18 |
Correct |
5 ms |
7116 KB |
Output is correct |
19 |
Correct |
18 ms |
15600 KB |
Output is correct |
20 |
Correct |
16 ms |
13260 KB |
Output is correct |
21 |
Correct |
20 ms |
16396 KB |
Output is correct |
22 |
Correct |
20 ms |
15588 KB |
Output is correct |
23 |
Correct |
21 ms |
14712 KB |
Output is correct |
24 |
Correct |
21 ms |
15820 KB |
Output is correct |
25 |
Correct |
21 ms |
16584 KB |
Output is correct |
26 |
Correct |
21 ms |
16264 KB |
Output is correct |
27 |
Correct |
37 ms |
26484 KB |
Output is correct |
28 |
Correct |
36 ms |
25380 KB |
Output is correct |
29 |
Correct |
36 ms |
26308 KB |
Output is correct |
30 |
Correct |
41 ms |
25472 KB |
Output is correct |
31 |
Correct |
41 ms |
25436 KB |
Output is correct |
32 |
Correct |
50 ms |
26316 KB |
Output is correct |
33 |
Correct |
381 ms |
200820 KB |
Output is correct |
34 |
Correct |
389 ms |
209988 KB |
Output is correct |
35 |
Correct |
403 ms |
205508 KB |
Output is correct |
36 |
Correct |
454 ms |
203708 KB |
Output is correct |
37 |
Correct |
476 ms |
212420 KB |
Output is correct |
38 |
Correct |
460 ms |
206916 KB |
Output is correct |
39 |
Correct |
1088 ms |
25584 KB |
Output is correct |
40 |
Correct |
1087 ms |
25664 KB |
Output is correct |
41 |
Correct |
1092 ms |
25564 KB |
Output is correct |
42 |
Correct |
300 ms |
92868 KB |
Output is correct |
43 |
Correct |
408 ms |
156680 KB |
Output is correct |
44 |
Correct |
424 ms |
156740 KB |
Output is correct |
45 |
Correct |
408 ms |
156676 KB |
Output is correct |
46 |
Correct |
411 ms |
156796 KB |
Output is correct |
47 |
Correct |
404 ms |
156684 KB |
Output is correct |
48 |
Correct |
419 ms |
156716 KB |
Output is correct |
49 |
Correct |
401 ms |
156836 KB |
Output is correct |
50 |
Correct |
419 ms |
156824 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4940 KB |
Output is correct |
2 |
Correct |
2 ms |
4940 KB |
Output is correct |
3 |
Correct |
3 ms |
4940 KB |
Output is correct |
4 |
Correct |
2 ms |
4940 KB |
Output is correct |
5 |
Correct |
2 ms |
4896 KB |
Output is correct |
6 |
Correct |
3 ms |
5196 KB |
Output is correct |
7 |
Correct |
3 ms |
5196 KB |
Output is correct |
8 |
Correct |
3 ms |
5132 KB |
Output is correct |
9 |
Correct |
3 ms |
5196 KB |
Output is correct |
10 |
Correct |
3 ms |
5196 KB |
Output is correct |
11 |
Correct |
3 ms |
5196 KB |
Output is correct |
12 |
Correct |
3 ms |
5196 KB |
Output is correct |
13 |
Correct |
3 ms |
5196 KB |
Output is correct |
14 |
Correct |
3 ms |
5196 KB |
Output is correct |
15 |
Correct |
3 ms |
5196 KB |
Output is correct |
16 |
Correct |
6 ms |
7372 KB |
Output is correct |
17 |
Correct |
6 ms |
7116 KB |
Output is correct |
18 |
Correct |
5 ms |
7116 KB |
Output is correct |
19 |
Correct |
18 ms |
15600 KB |
Output is correct |
20 |
Correct |
16 ms |
13260 KB |
Output is correct |
21 |
Correct |
20 ms |
16396 KB |
Output is correct |
22 |
Correct |
20 ms |
15588 KB |
Output is correct |
23 |
Correct |
21 ms |
14712 KB |
Output is correct |
24 |
Correct |
21 ms |
15820 KB |
Output is correct |
25 |
Correct |
21 ms |
16584 KB |
Output is correct |
26 |
Correct |
21 ms |
16264 KB |
Output is correct |
27 |
Correct |
946 ms |
359824 KB |
Output is correct |
28 |
Correct |
982 ms |
371516 KB |
Output is correct |
29 |
Correct |
954 ms |
350636 KB |
Output is correct |
30 |
Correct |
1004 ms |
388056 KB |
Output is correct |
31 |
Correct |
533 ms |
66228 KB |
Output is correct |
32 |
Correct |
882 ms |
212092 KB |
Output is correct |
33 |
Correct |
667 ms |
135984 KB |
Output is correct |
34 |
Correct |
725 ms |
158276 KB |
Output is correct |
35 |
Correct |
3 ms |
4940 KB |
Output is correct |
36 |
Correct |
494 ms |
229708 KB |
Output is correct |
37 |
Correct |
1634 ms |
657212 KB |
Output is correct |
38 |
Correct |
1611 ms |
657248 KB |
Output is correct |
39 |
Correct |
1495 ms |
588348 KB |
Output is correct |
40 |
Correct |
693 ms |
319772 KB |
Output is correct |
41 |
Correct |
356 ms |
170208 KB |
Output is correct |
42 |
Correct |
64 ms |
38528 KB |
Output is correct |
43 |
Correct |
1588 ms |
595984 KB |
Output is correct |
44 |
Correct |
1424 ms |
616636 KB |
Output is correct |
45 |
Correct |
1461 ms |
601944 KB |
Output is correct |
46 |
Correct |
1380 ms |
574832 KB |
Output is correct |
47 |
Correct |
1266 ms |
602308 KB |
Output is correct |
48 |
Correct |
1447 ms |
621044 KB |
Output is correct |
49 |
Correct |
1404 ms |
599304 KB |
Output is correct |
50 |
Correct |
1216 ms |
591656 KB |
Output is correct |
51 |
Correct |
37 ms |
26484 KB |
Output is correct |
52 |
Correct |
36 ms |
25380 KB |
Output is correct |
53 |
Correct |
36 ms |
26308 KB |
Output is correct |
54 |
Correct |
41 ms |
25472 KB |
Output is correct |
55 |
Correct |
41 ms |
25436 KB |
Output is correct |
56 |
Correct |
50 ms |
26316 KB |
Output is correct |
57 |
Correct |
381 ms |
200820 KB |
Output is correct |
58 |
Correct |
389 ms |
209988 KB |
Output is correct |
59 |
Correct |
403 ms |
205508 KB |
Output is correct |
60 |
Correct |
454 ms |
203708 KB |
Output is correct |
61 |
Correct |
476 ms |
212420 KB |
Output is correct |
62 |
Correct |
460 ms |
206916 KB |
Output is correct |
63 |
Correct |
1088 ms |
25584 KB |
Output is correct |
64 |
Correct |
1087 ms |
25664 KB |
Output is correct |
65 |
Correct |
1092 ms |
25564 KB |
Output is correct |
66 |
Correct |
300 ms |
92868 KB |
Output is correct |
67 |
Correct |
408 ms |
156680 KB |
Output is correct |
68 |
Correct |
424 ms |
156740 KB |
Output is correct |
69 |
Correct |
408 ms |
156676 KB |
Output is correct |
70 |
Correct |
411 ms |
156796 KB |
Output is correct |
71 |
Correct |
404 ms |
156684 KB |
Output is correct |
72 |
Correct |
419 ms |
156716 KB |
Output is correct |
73 |
Correct |
401 ms |
156836 KB |
Output is correct |
74 |
Correct |
419 ms |
156824 KB |
Output is correct |
75 |
Correct |
1337 ms |
614312 KB |
Output is correct |
76 |
Correct |
1089 ms |
473188 KB |
Output is correct |
77 |
Correct |
1112 ms |
524732 KB |
Output is correct |
78 |
Correct |
1194 ms |
604984 KB |
Output is correct |
79 |
Correct |
1486 ms |
620228 KB |
Output is correct |
80 |
Correct |
1189 ms |
593096 KB |
Output is correct |
81 |
Correct |
1549 ms |
604264 KB |
Output is correct |
82 |
Correct |
1552 ms |
609220 KB |
Output is correct |
83 |
Correct |
1548 ms |
616920 KB |
Output is correct |
84 |
Correct |
1489 ms |
572476 KB |
Output is correct |
85 |
Correct |
1548 ms |
625060 KB |
Output is correct |
86 |
Correct |
1579 ms |
619036 KB |
Output is correct |
87 |
Correct |
1517 ms |
544044 KB |
Output is correct |
88 |
Execution timed out |
3078 ms |
64704 KB |
Time limit exceeded |
89 |
Halted |
0 ms |
0 KB |
- |