#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MAXN = 6e5;
struct Circle
{
ll x, y, r; int p;
};
int N;
Circle A[MAXN+10], B[MAXN+10];
vector<ll> xcomp, ycomp;
bool vis[MAXN+10];
int getycomp(int x) { return lower_bound(ycomp.begin(), ycomp.end(), x)-ycomp.begin()+1; }
struct Node
{
ll x, y;
int par;
Node() : x(0), y(0), par(0) {}
Node(int x, int y) : x(x), y(y), par(0) {}
bool operator < (const Node &p) { return x<p.x; }
};
int Find(int x, vector<Node> &V)
{
if(x>=V.size()) return x;
if(V[x].par==x) return x;
return V[x].par=Find(V[x].par, V);
}
struct SEG
{
vector<Node> tree[MAXN*4+10];
void push(int node, int tl, int tr, int pos, ll p, int q)
{
if(tl==tr)
{
tree[node].push_back(Node(p, q));
return;
}
int mid=tl+tr>>1;
if(pos<=mid) push(node*2, tl, mid, pos, p, q);
else push(node*2+1, mid+1, tr, pos, p, q);
}
void init(int node, int tl, int tr)
{
if(tl==tr)
{
sort(tree[node].begin(), tree[node].end());
for(int i=0; i<tree[node].size(); i++) tree[node][i].par=i;
return;
}
int mid=tl+tr>>1;
init(node*2, tl, mid);
init(node*2+1, mid+1, tr);
tree[node].resize(tree[node*2].size()+tree[node*2+1].size());
merge(tree[node*2].begin(), tree[node*2].end(), tree[node*2+1].begin(), tree[node*2+1].end(), tree[node].begin());
for(int i=0; i<tree[node].size(); i++) tree[node][i].par=i;
}
void pop(int node, int tl, int tr, int l, int r, ll pl, ll pr, vector<int> &V)
{
if(r<tl || tr<l) return;
if(l<=tl && tr<=r)
{
for(int i=Find(lower_bound(tree[node].begin(), tree[node].end(), Node(pl, 0))-tree[node].begin(), tree[node]); i<tree[node].size() && tree[node][i].x<=pr; i=Find(i+1, tree[node]))
{
if(vis[tree[node][i].y])
{
int t=Find(i+1, tree[node]);
tree[node][i].par=t;
}
else
{
V.push_back(tree[node][i].y);
}
}
return;
}
int mid=tl+tr>>1;
pop(node*2, tl, mid, l, r, pl, pr, V);
pop(node*2+1, mid+1, tr, l, r, pl, pr, V);
}
}seg;
int ans[MAXN+10];
int main()
{
scanf("%d", &N);
for(int i=1; i<=N; i++) scanf("%lld%lld%lld", &A[i].x, &A[i].y, &A[i].r), A[i].p=i;
for(int i=1; i<=N; i++) B[i]=A[i];
sort(A+1, A+N+1, [&](const Circle &p, const Circle &q)
{
if(p.r!=q.r) return p.r>q.r;
return p.p<q.p;
});
for(int i=1; i<=N; i++)
{
xcomp.push_back(A[i].x-A[i].r);
xcomp.push_back(A[i].x+A[i].r);
ycomp.push_back(A[i].y-A[i].r);
ycomp.push_back(A[i].y+A[i].r);
}
sort(xcomp.begin(), xcomp.end());
xcomp.erase(unique(xcomp.begin(), xcomp.end()), xcomp.end());
sort(ycomp.begin(), ycomp.end());
ycomp.erase(unique(ycomp.begin(), ycomp.end()), ycomp.end());
for(int i=1; i<=N; i++)
{
int l=getycomp(A[i].y-A[i].r), r=getycomp(A[i].y+A[i].r);
seg.push(1, 1, ycomp.size(), l, A[i].x-A[i].r, A[i].p);
seg.push(1, 1, ycomp.size(), l, A[i].x+A[i].r, A[i].p);
seg.push(1, 1, ycomp.size(), r, A[i].x-A[i].r, A[i].p);
seg.push(1, 1, ycomp.size(), r, A[i].x+A[i].r, A[i].p);
}
seg.init(1, 1, ycomp.size());
for(int i=1; i<=N; i++)
{
if(vis[A[i].p]) continue;
ans[A[i].p]=A[i].p;
vis[A[i].p]=1;
vector<int> V;
int l=getycomp(A[i].y-A[i].r), r=getycomp(A[i].y+A[i].r);
seg.pop(1, 1, ycomp.size(), l, r, A[i].x-A[i].r, A[i].x+A[i].r, V);
sort(V.begin(), V.end());
V.erase(unique(V.begin(), V.end()), V.end());
for(auto it : V)
{
if((A[i].x-B[it].x)*(A[i].x-B[it].x)+(A[i].y-B[it].y)*(A[i].y-B[it].y)>(A[i].r+B[it].r)*(A[i].r+B[it].r)) continue;
ans[it]=A[i].p;
vis[it]=1;
}
}
for(int i=1; i<=N; i++) printf("%d ", ans[i]);
}
Compilation message
circle_selection.cpp: In function 'int Find(int, std::vector<Node>&)':
circle_selection.cpp:33:6: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<Node>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
33 | if(x>=V.size()) return x;
| ~^~~~~~~~~~
circle_selection.cpp: In member function 'void SEG::push(int, int, int, int, ll, int)':
circle_selection.cpp:48:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
48 | int mid=tl+tr>>1;
| ~~^~~
circle_selection.cpp: In member function 'void SEG::init(int, int, int)':
circle_selection.cpp:57:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<Node>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
57 | for(int i=0; i<tree[node].size(); i++) tree[node][i].par=i;
| ~^~~~~~~~~~~~~~~~~~
circle_selection.cpp:60:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
60 | int mid=tl+tr>>1;
| ~~^~~
circle_selection.cpp:65:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<Node>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
65 | for(int i=0; i<tree[node].size(); i++) tree[node][i].par=i;
| ~^~~~~~~~~~~~~~~~~~
circle_selection.cpp: In member function 'void SEG::pop(int, int, int, int, int, ll, ll, std::vector<int>&)':
circle_selection.cpp:72:116: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<Node>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
72 | for(int i=Find(lower_bound(tree[node].begin(), tree[node].end(), Node(pl, 0))-tree[node].begin(), tree[node]); i<tree[node].size() && tree[node][i].x<=pr; i=Find(i+1, tree[node]))
| ~^~~~~~~~~~~~~~~~~~
circle_selection.cpp:86:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
86 | int mid=tl+tr>>1;
| ~~^~~
circle_selection.cpp: In function 'int main()':
circle_selection.cpp:96:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
96 | scanf("%d", &N);
| ~~~~~^~~~~~~~~~
circle_selection.cpp:97:31: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
97 | for(int i=1; i<=N; i++) scanf("%lld%lld%lld", &A[i].x, &A[i].y, &A[i].r), A[i].p=i;
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
40 ms |
56696 KB |
Output is correct |
2 |
Correct |
37 ms |
56696 KB |
Output is correct |
3 |
Correct |
39 ms |
56700 KB |
Output is correct |
4 |
Correct |
38 ms |
56704 KB |
Output is correct |
5 |
Correct |
40 ms |
56696 KB |
Output is correct |
6 |
Correct |
39 ms |
56860 KB |
Output is correct |
7 |
Correct |
39 ms |
56832 KB |
Output is correct |
8 |
Correct |
39 ms |
56824 KB |
Output is correct |
9 |
Correct |
39 ms |
56960 KB |
Output is correct |
10 |
Correct |
38 ms |
56824 KB |
Output is correct |
11 |
Correct |
39 ms |
56832 KB |
Output is correct |
12 |
Correct |
40 ms |
56824 KB |
Output is correct |
13 |
Correct |
38 ms |
56824 KB |
Output is correct |
14 |
Correct |
40 ms |
56832 KB |
Output is correct |
15 |
Correct |
39 ms |
56824 KB |
Output is correct |
16 |
Correct |
42 ms |
57976 KB |
Output is correct |
17 |
Correct |
41 ms |
58104 KB |
Output is correct |
18 |
Correct |
41 ms |
58060 KB |
Output is correct |
19 |
Correct |
59 ms |
64632 KB |
Output is correct |
20 |
Correct |
56 ms |
64632 KB |
Output is correct |
21 |
Correct |
57 ms |
64632 KB |
Output is correct |
22 |
Correct |
58 ms |
64504 KB |
Output is correct |
23 |
Correct |
58 ms |
64504 KB |
Output is correct |
24 |
Correct |
59 ms |
64468 KB |
Output is correct |
25 |
Correct |
57 ms |
64508 KB |
Output is correct |
26 |
Correct |
57 ms |
64504 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1341 ms |
684056 KB |
Output is correct |
2 |
Correct |
1362 ms |
688708 KB |
Output is correct |
3 |
Correct |
1355 ms |
689456 KB |
Output is correct |
4 |
Correct |
1359 ms |
690468 KB |
Output is correct |
5 |
Correct |
666 ms |
313648 KB |
Output is correct |
6 |
Correct |
973 ms |
335524 KB |
Output is correct |
7 |
Correct |
741 ms |
353956 KB |
Output is correct |
8 |
Correct |
758 ms |
340088 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
39 ms |
56704 KB |
Output is correct |
2 |
Correct |
735 ms |
251096 KB |
Output is correct |
3 |
Correct |
2364 ms |
685036 KB |
Output is correct |
4 |
Correct |
2366 ms |
686116 KB |
Output is correct |
5 |
Correct |
2325 ms |
668076 KB |
Output is correct |
6 |
Correct |
1076 ms |
371268 KB |
Output is correct |
7 |
Correct |
526 ms |
215148 KB |
Output is correct |
8 |
Correct |
113 ms |
85608 KB |
Output is correct |
9 |
Correct |
2389 ms |
686116 KB |
Output is correct |
10 |
Correct |
2350 ms |
686388 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2166 ms |
678564 KB |
Output is correct |
2 |
Correct |
1874 ms |
685128 KB |
Output is correct |
3 |
Correct |
1849 ms |
686116 KB |
Output is correct |
4 |
Correct |
1925 ms |
685428 KB |
Output is correct |
5 |
Correct |
2021 ms |
685580 KB |
Output is correct |
6 |
Correct |
1809 ms |
685996 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
40 ms |
56696 KB |
Output is correct |
2 |
Correct |
37 ms |
56696 KB |
Output is correct |
3 |
Correct |
39 ms |
56700 KB |
Output is correct |
4 |
Correct |
38 ms |
56704 KB |
Output is correct |
5 |
Correct |
40 ms |
56696 KB |
Output is correct |
6 |
Correct |
39 ms |
56860 KB |
Output is correct |
7 |
Correct |
39 ms |
56832 KB |
Output is correct |
8 |
Correct |
39 ms |
56824 KB |
Output is correct |
9 |
Correct |
39 ms |
56960 KB |
Output is correct |
10 |
Correct |
38 ms |
56824 KB |
Output is correct |
11 |
Correct |
39 ms |
56832 KB |
Output is correct |
12 |
Correct |
40 ms |
56824 KB |
Output is correct |
13 |
Correct |
38 ms |
56824 KB |
Output is correct |
14 |
Correct |
40 ms |
56832 KB |
Output is correct |
15 |
Correct |
39 ms |
56824 KB |
Output is correct |
16 |
Correct |
42 ms |
57976 KB |
Output is correct |
17 |
Correct |
41 ms |
58104 KB |
Output is correct |
18 |
Correct |
41 ms |
58060 KB |
Output is correct |
19 |
Correct |
59 ms |
64632 KB |
Output is correct |
20 |
Correct |
56 ms |
64632 KB |
Output is correct |
21 |
Correct |
57 ms |
64632 KB |
Output is correct |
22 |
Correct |
58 ms |
64504 KB |
Output is correct |
23 |
Correct |
58 ms |
64504 KB |
Output is correct |
24 |
Correct |
59 ms |
64468 KB |
Output is correct |
25 |
Correct |
57 ms |
64508 KB |
Output is correct |
26 |
Correct |
57 ms |
64504 KB |
Output is correct |
27 |
Correct |
81 ms |
73216 KB |
Output is correct |
28 |
Correct |
82 ms |
73372 KB |
Output is correct |
29 |
Correct |
80 ms |
73336 KB |
Output is correct |
30 |
Correct |
80 ms |
73076 KB |
Output is correct |
31 |
Correct |
82 ms |
73076 KB |
Output is correct |
32 |
Correct |
81 ms |
73204 KB |
Output is correct |
33 |
Correct |
566 ms |
253136 KB |
Output is correct |
34 |
Correct |
554 ms |
254168 KB |
Output is correct |
35 |
Correct |
573 ms |
253272 KB |
Output is correct |
36 |
Correct |
680 ms |
251736 KB |
Output is correct |
37 |
Correct |
638 ms |
251600 KB |
Output is correct |
38 |
Correct |
679 ms |
251736 KB |
Output is correct |
39 |
Correct |
330 ms |
173140 KB |
Output is correct |
40 |
Correct |
324 ms |
172884 KB |
Output is correct |
41 |
Correct |
324 ms |
172632 KB |
Output is correct |
42 |
Correct |
319 ms |
183640 KB |
Output is correct |
43 |
Correct |
586 ms |
251756 KB |
Output is correct |
44 |
Correct |
579 ms |
251600 KB |
Output is correct |
45 |
Correct |
585 ms |
251648 KB |
Output is correct |
46 |
Correct |
590 ms |
251736 KB |
Output is correct |
47 |
Correct |
593 ms |
251736 KB |
Output is correct |
48 |
Correct |
589 ms |
251608 KB |
Output is correct |
49 |
Correct |
585 ms |
251736 KB |
Output is correct |
50 |
Correct |
584 ms |
249144 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
40 ms |
56696 KB |
Output is correct |
2 |
Correct |
37 ms |
56696 KB |
Output is correct |
3 |
Correct |
39 ms |
56700 KB |
Output is correct |
4 |
Correct |
38 ms |
56704 KB |
Output is correct |
5 |
Correct |
40 ms |
56696 KB |
Output is correct |
6 |
Correct |
39 ms |
56860 KB |
Output is correct |
7 |
Correct |
39 ms |
56832 KB |
Output is correct |
8 |
Correct |
39 ms |
56824 KB |
Output is correct |
9 |
Correct |
39 ms |
56960 KB |
Output is correct |
10 |
Correct |
38 ms |
56824 KB |
Output is correct |
11 |
Correct |
39 ms |
56832 KB |
Output is correct |
12 |
Correct |
40 ms |
56824 KB |
Output is correct |
13 |
Correct |
38 ms |
56824 KB |
Output is correct |
14 |
Correct |
40 ms |
56832 KB |
Output is correct |
15 |
Correct |
39 ms |
56824 KB |
Output is correct |
16 |
Correct |
42 ms |
57976 KB |
Output is correct |
17 |
Correct |
41 ms |
58104 KB |
Output is correct |
18 |
Correct |
41 ms |
58060 KB |
Output is correct |
19 |
Correct |
59 ms |
64632 KB |
Output is correct |
20 |
Correct |
56 ms |
64632 KB |
Output is correct |
21 |
Correct |
57 ms |
64632 KB |
Output is correct |
22 |
Correct |
58 ms |
64504 KB |
Output is correct |
23 |
Correct |
58 ms |
64504 KB |
Output is correct |
24 |
Correct |
59 ms |
64468 KB |
Output is correct |
25 |
Correct |
57 ms |
64508 KB |
Output is correct |
26 |
Correct |
57 ms |
64504 KB |
Output is correct |
27 |
Correct |
1341 ms |
684056 KB |
Output is correct |
28 |
Correct |
1362 ms |
688708 KB |
Output is correct |
29 |
Correct |
1355 ms |
689456 KB |
Output is correct |
30 |
Correct |
1359 ms |
690468 KB |
Output is correct |
31 |
Correct |
666 ms |
313648 KB |
Output is correct |
32 |
Correct |
973 ms |
335524 KB |
Output is correct |
33 |
Correct |
741 ms |
353956 KB |
Output is correct |
34 |
Correct |
758 ms |
340088 KB |
Output is correct |
35 |
Correct |
39 ms |
56704 KB |
Output is correct |
36 |
Correct |
735 ms |
251096 KB |
Output is correct |
37 |
Correct |
2364 ms |
685036 KB |
Output is correct |
38 |
Correct |
2366 ms |
686116 KB |
Output is correct |
39 |
Correct |
2325 ms |
668076 KB |
Output is correct |
40 |
Correct |
1076 ms |
371268 KB |
Output is correct |
41 |
Correct |
526 ms |
215148 KB |
Output is correct |
42 |
Correct |
113 ms |
85608 KB |
Output is correct |
43 |
Correct |
2389 ms |
686116 KB |
Output is correct |
44 |
Correct |
2350 ms |
686388 KB |
Output is correct |
45 |
Correct |
2166 ms |
678564 KB |
Output is correct |
46 |
Correct |
1874 ms |
685128 KB |
Output is correct |
47 |
Correct |
1849 ms |
686116 KB |
Output is correct |
48 |
Correct |
1925 ms |
685428 KB |
Output is correct |
49 |
Correct |
2021 ms |
685580 KB |
Output is correct |
50 |
Correct |
1809 ms |
685996 KB |
Output is correct |
51 |
Correct |
81 ms |
73216 KB |
Output is correct |
52 |
Correct |
82 ms |
73372 KB |
Output is correct |
53 |
Correct |
80 ms |
73336 KB |
Output is correct |
54 |
Correct |
80 ms |
73076 KB |
Output is correct |
55 |
Correct |
82 ms |
73076 KB |
Output is correct |
56 |
Correct |
81 ms |
73204 KB |
Output is correct |
57 |
Correct |
566 ms |
253136 KB |
Output is correct |
58 |
Correct |
554 ms |
254168 KB |
Output is correct |
59 |
Correct |
573 ms |
253272 KB |
Output is correct |
60 |
Correct |
680 ms |
251736 KB |
Output is correct |
61 |
Correct |
638 ms |
251600 KB |
Output is correct |
62 |
Correct |
679 ms |
251736 KB |
Output is correct |
63 |
Correct |
330 ms |
173140 KB |
Output is correct |
64 |
Correct |
324 ms |
172884 KB |
Output is correct |
65 |
Correct |
324 ms |
172632 KB |
Output is correct |
66 |
Correct |
319 ms |
183640 KB |
Output is correct |
67 |
Correct |
586 ms |
251756 KB |
Output is correct |
68 |
Correct |
579 ms |
251600 KB |
Output is correct |
69 |
Correct |
585 ms |
251648 KB |
Output is correct |
70 |
Correct |
590 ms |
251736 KB |
Output is correct |
71 |
Correct |
593 ms |
251736 KB |
Output is correct |
72 |
Correct |
589 ms |
251608 KB |
Output is correct |
73 |
Correct |
585 ms |
251736 KB |
Output is correct |
74 |
Correct |
584 ms |
249144 KB |
Output is correct |
75 |
Correct |
1865 ms |
691888 KB |
Output is correct |
76 |
Correct |
1552 ms |
690736 KB |
Output is correct |
77 |
Correct |
1841 ms |
695688 KB |
Output is correct |
78 |
Correct |
1837 ms |
692780 KB |
Output is correct |
79 |
Correct |
1873 ms |
687336 KB |
Output is correct |
80 |
Correct |
1805 ms |
693040 KB |
Output is correct |
81 |
Correct |
2240 ms |
686000 KB |
Output is correct |
82 |
Correct |
2492 ms |
685744 KB |
Output is correct |
83 |
Correct |
2316 ms |
686144 KB |
Output is correct |
84 |
Correct |
2478 ms |
686256 KB |
Output is correct |
85 |
Correct |
2242 ms |
685988 KB |
Output is correct |
86 |
Correct |
2422 ms |
685996 KB |
Output is correct |
87 |
Correct |
2313 ms |
686124 KB |
Output is correct |
88 |
Correct |
1037 ms |
424468 KB |
Output is correct |
89 |
Correct |
1008 ms |
424112 KB |
Output is correct |
90 |
Correct |
1016 ms |
423980 KB |
Output is correct |
91 |
Correct |
1002 ms |
422624 KB |
Output is correct |
92 |
Correct |
1071 ms |
424032 KB |
Output is correct |
93 |
Correct |
1710 ms |
402596 KB |
Output is correct |
94 |
Correct |
1878 ms |
685460 KB |
Output is correct |
95 |
Correct |
1679 ms |
419760 KB |
Output is correct |
96 |
Correct |
1862 ms |
412832 KB |
Output is correct |
97 |
Correct |
1853 ms |
684884 KB |
Output is correct |
98 |
Correct |
1266 ms |
364672 KB |
Output is correct |
99 |
Correct |
1978 ms |
375712 KB |
Output is correct |
100 |
Correct |
1363 ms |
393796 KB |
Output is correct |
101 |
Correct |
1629 ms |
420808 KB |
Output is correct |
102 |
Correct |
2019 ms |
356168 KB |
Output is correct |
103 |
Correct |
1976 ms |
684888 KB |
Output is correct |
104 |
Correct |
2035 ms |
422308 KB |
Output is correct |
105 |
Correct |
978 ms |
466096 KB |
Output is correct |
106 |
Correct |
1834 ms |
685668 KB |
Output is correct |
107 |
Correct |
1816 ms |
685768 KB |
Output is correct |
108 |
Correct |
1821 ms |
685808 KB |
Output is correct |
109 |
Correct |
1833 ms |
685604 KB |
Output is correct |
110 |
Correct |
1836 ms |
685864 KB |
Output is correct |
111 |
Correct |
1814 ms |
685732 KB |
Output is correct |
112 |
Correct |
1818 ms |
685744 KB |
Output is correct |
113 |
Correct |
1833 ms |
685592 KB |
Output is correct |
114 |
Correct |
1812 ms |
685720 KB |
Output is correct |
115 |
Correct |
1832 ms |
685604 KB |
Output is correct |
116 |
Correct |
1899 ms |
685760 KB |
Output is correct |