#include <bits/stdc++.h>
#define mp make_pair
#define eb emplace_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define svec(x) sort(all(x))
#define press(x) x.erase(unique(all(x)), x.end());
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
int n, ans[300010], l[300010], r[300010];
pair<pii, pii> arr[300010];
vector<int> idx;
bool cmp(pair<pii, pii> a, pair<pii, pii> b){return mp(a.S.F, -a.S.S)>mp(b.S.F, -b.S.S);}
inline bool is_con(int a, int b){
LL d=(LL)(arr[a].F.F-arr[b].F.F)*(arr[a].F.F-arr[b].F.F)+(LL)(arr[a].F.S-arr[b].F.S)*(arr[a].F.S-arr[b].F.S);
LL rs=(LL)(arr[a].S.F+arr[b].S.F)*(arr[a].S.F+arr[b].S.F);
return rs>=d;
}
struct NODE{
vector<pii> vc;
vector<int> par;
int findpar(int num){return num==par[num]?num:par[num]=findpar(par[num]);}
void query(int s, int e, int num){
int nw=lower_bound(all(vc), mp(s, 0))-vc.begin();
while(1){
nw=findpar(nw);
//printf("%d %d\n", nw);
if(nw>=vc.size()||vc[nw].F>e)break;
int nw2=vc[nw].S;
if(ans[arr[nw2].S.S])par[nw]=findpar(nw+1);
else if(is_con(nw2, num)){
par[nw]=findpar(nw+1);
ans[arr[nw2].S.S]=arr[num].S.S;
}
nw++;
}
}
void init(){
//svec(vc);
par.resize(vc.size()+1);
for(int i=0; i<par.size(); i++)par[i]=i;
}
}tree[2400010];
void update(int point, int s, int e, int num, pii val){
if(s==e){
tree[point].vc.eb(val);
return;
}
if(num<=(s+e)/2)update(point*2, s, (s+e)/2, num, val);
else update(point*2+1, (s+e)/2+1, e, num, val);
}
void query(int point, int s, int e, int sx, int ex, int sy, int ey, int num){
if(e<sx||s>ex)return;
if(sx<=s&&e<=ex){
tree[point].query(sy, ey, num);
return;
}
query(point*2, s, (s+e)/2, sx, ex, sy, ey, num);
query(point*2+1, (s+e)/2+1, e, sx, ex, sy, ey, num);
}
void init(int point, int s, int e){
if(s==e){
svec(tree[point].vc);
tree[point].init();
}
if(s==e)return;
init(point*2, s, (s+e)/2);
init(point*2+1, (s+e)/2+1, e);
int sl=tree[point*2].vc.size(), sr=tree[point*2+1].vc.size();
tree[point].vc.resize(sl+sr);
for(int i=0, j=0, k=0; i<sl||j<sr;){
if(j==sr||(i<sl&&tree[point*2].vc[i]<tree[point*2+1].vc[j]))tree[point].vc[k++]=tree[point*2].vc[i++];
else tree[point].vc[k++]=tree[point*2+1].vc[j++];
}
tree[point].init();
}
inline int readChar();
template<class T=int> inline T readInt();
static const int buf_size=4096;
inline int getChar() {
static char buf[buf_size];
static int len=0, pos=0;
if(pos==len)pos=0, len=fread(buf, 1, buf_size, stdin);
if(pos==len)return -1;
return buf[pos++];
}
inline int readChar() {
int c=getChar();
while(c<=32)c=getChar();
return c;
}
template <class T>
inline T readInt() {
int s=1, c=readChar();
T x=0;
if(c=='-')s=-1, c=getChar();
while('0'<=c&&c<='9')x=x*10+c-'0', c=getChar();
return s==1?x:-x;
}
vector<pair<pii, int> > updlist;
int main(){
//scanf("%d", &n);
n=readInt();
for(int i=1; i<=n; i++){
//scanf("%d %d %d", &arr[i].F.F, &arr[i].F.S, &arr[i].S.F);
arr[i].F.F=readInt();
arr[i].F.S=readInt();
arr[i].S.F=readInt();
idx.eb(arr[i].F.F-arr[i].S.F);
idx.eb(arr[i].F.F+arr[i].S.F);
arr[i].S.S=i;
}
sort(arr+1, arr+n+1, cmp);
svec(idx); press(idx);
for(int i=1; i<=n; i++){
l[i]=lower_bound(all(idx), arr[i].F.F-arr[i].S.F)-idx.begin()+1;
r[i]=lower_bound(all(idx), arr[i].F.F+arr[i].S.F)-idx.begin()+1;
update(1, 1, idx.size(), l[i], mp(arr[i].F.S-arr[i].S.F, i));
update(1, 1, idx.size(), l[i], mp(arr[i].F.S+arr[i].S.F, i));
update(1, 1, idx.size(), r[i], mp(arr[i].F.S-arr[i].S.F, i));
update(1, 1, idx.size(), r[i], mp(arr[i].F.S+arr[i].S.F, i));
}
init(1, 1, idx.size());
for(int i=1; i<=n; i++){
if(ans[arr[i].S.S])continue;
query(1, 1, idx.size(), l[i], r[i], arr[i].F.S-arr[i].S.F, arr[i].F.S+arr[i].S.F, i);
}
for(int i=1; i<=n; i++)printf("%d ", ans[i]);
}
Compilation message
circle_selection.cpp: In member function 'void NODE::query(int, int, int)':
circle_selection.cpp:32:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
32 | if(nw>=vc.size()||vc[nw].F>e)break;
| ~~^~~~~~~~~~~
circle_selection.cpp: In member function 'void NODE::init()':
circle_selection.cpp:45:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
45 | for(int i=0; i<par.size(); i++)par[i]=i;
| ~^~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
74 ms |
113020 KB |
Output is correct |
2 |
Correct |
85 ms |
113016 KB |
Output is correct |
3 |
Correct |
74 ms |
113020 KB |
Output is correct |
4 |
Correct |
74 ms |
113016 KB |
Output is correct |
5 |
Correct |
74 ms |
113016 KB |
Output is correct |
6 |
Correct |
75 ms |
113144 KB |
Output is correct |
7 |
Correct |
76 ms |
113144 KB |
Output is correct |
8 |
Correct |
75 ms |
113144 KB |
Output is correct |
9 |
Correct |
76 ms |
113144 KB |
Output is correct |
10 |
Correct |
77 ms |
113144 KB |
Output is correct |
11 |
Correct |
77 ms |
113144 KB |
Output is correct |
12 |
Correct |
77 ms |
113144 KB |
Output is correct |
13 |
Correct |
79 ms |
113144 KB |
Output is correct |
14 |
Correct |
78 ms |
113144 KB |
Output is correct |
15 |
Correct |
74 ms |
113068 KB |
Output is correct |
16 |
Correct |
78 ms |
113788 KB |
Output is correct |
17 |
Correct |
77 ms |
113784 KB |
Output is correct |
18 |
Correct |
77 ms |
113788 KB |
Output is correct |
19 |
Correct |
90 ms |
117496 KB |
Output is correct |
20 |
Correct |
88 ms |
117496 KB |
Output is correct |
21 |
Correct |
94 ms |
117496 KB |
Output is correct |
22 |
Correct |
90 ms |
117496 KB |
Output is correct |
23 |
Correct |
91 ms |
117496 KB |
Output is correct |
24 |
Correct |
95 ms |
117496 KB |
Output is correct |
25 |
Correct |
92 ms |
117496 KB |
Output is correct |
26 |
Correct |
97 ms |
117496 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1636 ms |
456436 KB |
Output is correct |
2 |
Correct |
1647 ms |
455516 KB |
Output is correct |
3 |
Correct |
1679 ms |
455568 KB |
Output is correct |
4 |
Correct |
1611 ms |
455544 KB |
Output is correct |
5 |
Correct |
1347 ms |
417760 KB |
Output is correct |
6 |
Correct |
1617 ms |
453888 KB |
Output is correct |
7 |
Correct |
1474 ms |
446696 KB |
Output is correct |
8 |
Correct |
1509 ms |
450184 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
76 ms |
113016 KB |
Output is correct |
2 |
Correct |
625 ms |
220908 KB |
Output is correct |
3 |
Correct |
1900 ms |
456296 KB |
Output is correct |
4 |
Correct |
1876 ms |
455468 KB |
Output is correct |
5 |
Correct |
1920 ms |
445388 KB |
Output is correct |
6 |
Correct |
939 ms |
285668 KB |
Output is correct |
7 |
Correct |
487 ms |
200812 KB |
Output is correct |
8 |
Correct |
142 ms |
129524 KB |
Output is correct |
9 |
Correct |
2012 ms |
455464 KB |
Output is correct |
10 |
Correct |
2016 ms |
455456 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1885 ms |
456828 KB |
Output is correct |
2 |
Correct |
1576 ms |
455140 KB |
Output is correct |
3 |
Correct |
1694 ms |
455004 KB |
Output is correct |
4 |
Correct |
1619 ms |
455452 KB |
Output is correct |
5 |
Correct |
1572 ms |
455584 KB |
Output is correct |
6 |
Correct |
1628 ms |
454596 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
74 ms |
113020 KB |
Output is correct |
2 |
Correct |
85 ms |
113016 KB |
Output is correct |
3 |
Correct |
74 ms |
113020 KB |
Output is correct |
4 |
Correct |
74 ms |
113016 KB |
Output is correct |
5 |
Correct |
74 ms |
113016 KB |
Output is correct |
6 |
Correct |
75 ms |
113144 KB |
Output is correct |
7 |
Correct |
76 ms |
113144 KB |
Output is correct |
8 |
Correct |
75 ms |
113144 KB |
Output is correct |
9 |
Correct |
76 ms |
113144 KB |
Output is correct |
10 |
Correct |
77 ms |
113144 KB |
Output is correct |
11 |
Correct |
77 ms |
113144 KB |
Output is correct |
12 |
Correct |
77 ms |
113144 KB |
Output is correct |
13 |
Correct |
79 ms |
113144 KB |
Output is correct |
14 |
Correct |
78 ms |
113144 KB |
Output is correct |
15 |
Correct |
74 ms |
113068 KB |
Output is correct |
16 |
Correct |
78 ms |
113788 KB |
Output is correct |
17 |
Correct |
77 ms |
113784 KB |
Output is correct |
18 |
Correct |
77 ms |
113788 KB |
Output is correct |
19 |
Correct |
90 ms |
117496 KB |
Output is correct |
20 |
Correct |
88 ms |
117496 KB |
Output is correct |
21 |
Correct |
94 ms |
117496 KB |
Output is correct |
22 |
Correct |
90 ms |
117496 KB |
Output is correct |
23 |
Correct |
91 ms |
117496 KB |
Output is correct |
24 |
Correct |
95 ms |
117496 KB |
Output is correct |
25 |
Correct |
92 ms |
117496 KB |
Output is correct |
26 |
Correct |
97 ms |
117496 KB |
Output is correct |
27 |
Correct |
114 ms |
122480 KB |
Output is correct |
28 |
Correct |
124 ms |
122488 KB |
Output is correct |
29 |
Correct |
132 ms |
122488 KB |
Output is correct |
30 |
Correct |
129 ms |
122616 KB |
Output is correct |
31 |
Correct |
121 ms |
122504 KB |
Output is correct |
32 |
Correct |
126 ms |
122488 KB |
Output is correct |
33 |
Correct |
572 ms |
222312 KB |
Output is correct |
34 |
Correct |
520 ms |
221804 KB |
Output is correct |
35 |
Correct |
532 ms |
221832 KB |
Output is correct |
36 |
Correct |
575 ms |
221672 KB |
Output is correct |
37 |
Correct |
604 ms |
221728 KB |
Output is correct |
38 |
Correct |
591 ms |
221676 KB |
Output is correct |
39 |
Correct |
320 ms |
169740 KB |
Output is correct |
40 |
Correct |
295 ms |
169832 KB |
Output is correct |
41 |
Correct |
336 ms |
169836 KB |
Output is correct |
42 |
Correct |
290 ms |
175464 KB |
Output is correct |
43 |
Correct |
537 ms |
222188 KB |
Output is correct |
44 |
Correct |
532 ms |
222316 KB |
Output is correct |
45 |
Correct |
647 ms |
222184 KB |
Output is correct |
46 |
Correct |
650 ms |
222184 KB |
Output is correct |
47 |
Correct |
651 ms |
222188 KB |
Output is correct |
48 |
Correct |
613 ms |
222188 KB |
Output is correct |
49 |
Correct |
642 ms |
221932 KB |
Output is correct |
50 |
Correct |
530 ms |
221932 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
74 ms |
113020 KB |
Output is correct |
2 |
Correct |
85 ms |
113016 KB |
Output is correct |
3 |
Correct |
74 ms |
113020 KB |
Output is correct |
4 |
Correct |
74 ms |
113016 KB |
Output is correct |
5 |
Correct |
74 ms |
113016 KB |
Output is correct |
6 |
Correct |
75 ms |
113144 KB |
Output is correct |
7 |
Correct |
76 ms |
113144 KB |
Output is correct |
8 |
Correct |
75 ms |
113144 KB |
Output is correct |
9 |
Correct |
76 ms |
113144 KB |
Output is correct |
10 |
Correct |
77 ms |
113144 KB |
Output is correct |
11 |
Correct |
77 ms |
113144 KB |
Output is correct |
12 |
Correct |
77 ms |
113144 KB |
Output is correct |
13 |
Correct |
79 ms |
113144 KB |
Output is correct |
14 |
Correct |
78 ms |
113144 KB |
Output is correct |
15 |
Correct |
74 ms |
113068 KB |
Output is correct |
16 |
Correct |
78 ms |
113788 KB |
Output is correct |
17 |
Correct |
77 ms |
113784 KB |
Output is correct |
18 |
Correct |
77 ms |
113788 KB |
Output is correct |
19 |
Correct |
90 ms |
117496 KB |
Output is correct |
20 |
Correct |
88 ms |
117496 KB |
Output is correct |
21 |
Correct |
94 ms |
117496 KB |
Output is correct |
22 |
Correct |
90 ms |
117496 KB |
Output is correct |
23 |
Correct |
91 ms |
117496 KB |
Output is correct |
24 |
Correct |
95 ms |
117496 KB |
Output is correct |
25 |
Correct |
92 ms |
117496 KB |
Output is correct |
26 |
Correct |
97 ms |
117496 KB |
Output is correct |
27 |
Correct |
1636 ms |
456436 KB |
Output is correct |
28 |
Correct |
1647 ms |
455516 KB |
Output is correct |
29 |
Correct |
1679 ms |
455568 KB |
Output is correct |
30 |
Correct |
1611 ms |
455544 KB |
Output is correct |
31 |
Correct |
1347 ms |
417760 KB |
Output is correct |
32 |
Correct |
1617 ms |
453888 KB |
Output is correct |
33 |
Correct |
1474 ms |
446696 KB |
Output is correct |
34 |
Correct |
1509 ms |
450184 KB |
Output is correct |
35 |
Correct |
76 ms |
113016 KB |
Output is correct |
36 |
Correct |
625 ms |
220908 KB |
Output is correct |
37 |
Correct |
1900 ms |
456296 KB |
Output is correct |
38 |
Correct |
1876 ms |
455468 KB |
Output is correct |
39 |
Correct |
1920 ms |
445388 KB |
Output is correct |
40 |
Correct |
939 ms |
285668 KB |
Output is correct |
41 |
Correct |
487 ms |
200812 KB |
Output is correct |
42 |
Correct |
142 ms |
129524 KB |
Output is correct |
43 |
Correct |
2012 ms |
455464 KB |
Output is correct |
44 |
Correct |
2016 ms |
455456 KB |
Output is correct |
45 |
Correct |
1885 ms |
456828 KB |
Output is correct |
46 |
Correct |
1576 ms |
455140 KB |
Output is correct |
47 |
Correct |
1694 ms |
455004 KB |
Output is correct |
48 |
Correct |
1619 ms |
455452 KB |
Output is correct |
49 |
Correct |
1572 ms |
455584 KB |
Output is correct |
50 |
Correct |
1628 ms |
454596 KB |
Output is correct |
51 |
Correct |
114 ms |
122480 KB |
Output is correct |
52 |
Correct |
124 ms |
122488 KB |
Output is correct |
53 |
Correct |
132 ms |
122488 KB |
Output is correct |
54 |
Correct |
129 ms |
122616 KB |
Output is correct |
55 |
Correct |
121 ms |
122504 KB |
Output is correct |
56 |
Correct |
126 ms |
122488 KB |
Output is correct |
57 |
Correct |
572 ms |
222312 KB |
Output is correct |
58 |
Correct |
520 ms |
221804 KB |
Output is correct |
59 |
Correct |
532 ms |
221832 KB |
Output is correct |
60 |
Correct |
575 ms |
221672 KB |
Output is correct |
61 |
Correct |
604 ms |
221728 KB |
Output is correct |
62 |
Correct |
591 ms |
221676 KB |
Output is correct |
63 |
Correct |
320 ms |
169740 KB |
Output is correct |
64 |
Correct |
295 ms |
169832 KB |
Output is correct |
65 |
Correct |
336 ms |
169836 KB |
Output is correct |
66 |
Correct |
290 ms |
175464 KB |
Output is correct |
67 |
Correct |
537 ms |
222188 KB |
Output is correct |
68 |
Correct |
532 ms |
222316 KB |
Output is correct |
69 |
Correct |
647 ms |
222184 KB |
Output is correct |
70 |
Correct |
650 ms |
222184 KB |
Output is correct |
71 |
Correct |
651 ms |
222188 KB |
Output is correct |
72 |
Correct |
613 ms |
222188 KB |
Output is correct |
73 |
Correct |
642 ms |
221932 KB |
Output is correct |
74 |
Correct |
530 ms |
221932 KB |
Output is correct |
75 |
Correct |
1647 ms |
455320 KB |
Output is correct |
76 |
Correct |
1647 ms |
455772 KB |
Output is correct |
77 |
Correct |
1501 ms |
455644 KB |
Output is correct |
78 |
Correct |
1535 ms |
455392 KB |
Output is correct |
79 |
Correct |
1661 ms |
455644 KB |
Output is correct |
80 |
Correct |
1574 ms |
455516 KB |
Output is correct |
81 |
Correct |
2011 ms |
455828 KB |
Output is correct |
82 |
Correct |
1843 ms |
455904 KB |
Output is correct |
83 |
Correct |
1859 ms |
455772 KB |
Output is correct |
84 |
Correct |
2160 ms |
455644 KB |
Output is correct |
85 |
Correct |
1951 ms |
455920 KB |
Output is correct |
86 |
Correct |
1887 ms |
455584 KB |
Output is correct |
87 |
Correct |
2384 ms |
454616 KB |
Output is correct |
88 |
Correct |
850 ms |
292828 KB |
Output is correct |
89 |
Correct |
823 ms |
293216 KB |
Output is correct |
90 |
Correct |
883 ms |
292960 KB |
Output is correct |
91 |
Correct |
877 ms |
293064 KB |
Output is correct |
92 |
Correct |
837 ms |
292700 KB |
Output is correct |
93 |
Correct |
1688 ms |
462020 KB |
Output is correct |
94 |
Correct |
1421 ms |
253540 KB |
Output is correct |
95 |
Correct |
1710 ms |
462044 KB |
Output is correct |
96 |
Correct |
1683 ms |
461808 KB |
Output is correct |
97 |
Correct |
1149 ms |
285084 KB |
Output is correct |
98 |
Correct |
1621 ms |
460636 KB |
Output is correct |
99 |
Correct |
1638 ms |
462272 KB |
Output is correct |
100 |
Correct |
1606 ms |
462172 KB |
Output is correct |
101 |
Correct |
1673 ms |
458304 KB |
Output is correct |
102 |
Correct |
1645 ms |
462044 KB |
Output is correct |
103 |
Correct |
1487 ms |
272252 KB |
Output is correct |
104 |
Correct |
1645 ms |
461980 KB |
Output is correct |
105 |
Correct |
765 ms |
313948 KB |
Output is correct |
106 |
Correct |
1566 ms |
462864 KB |
Output is correct |
107 |
Correct |
1694 ms |
462776 KB |
Output is correct |
108 |
Correct |
1927 ms |
462912 KB |
Output is correct |
109 |
Correct |
1767 ms |
462820 KB |
Output is correct |
110 |
Correct |
1598 ms |
462856 KB |
Output is correct |
111 |
Correct |
1832 ms |
463068 KB |
Output is correct |
112 |
Correct |
1574 ms |
462780 KB |
Output is correct |
113 |
Correct |
1834 ms |
463020 KB |
Output is correct |
114 |
Correct |
1602 ms |
462940 KB |
Output is correct |
115 |
Correct |
1662 ms |
462972 KB |
Output is correct |
116 |
Correct |
1531 ms |
463056 KB |
Output is correct |