#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;
typedef pair<int, LL> pil;
typedef pair<LL, int> pli;
typedef pair<LL, LL> pll;
const int INF=1e9;
const LL LLINF=1e18;
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);}
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))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){
tree[point].vc.eb(val);
if(s==e)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){
tree[point].init();
if(s==e)return;
init(point*2, s, (s+e)/2);
init(point*2+1, (s+e)/2+1, e);
}
int main(){
scanf("%d", &n);
for(int i=1; i<=n; i++){
scanf("%d %d %d", &arr[i].F.F, &arr[i].F.S, &arr[i].S.F);
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:37: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]
37 | if(nw>=vc.size()||vc[nw].F>e)break;
| ~~^~~~~~~~~~~
circle_selection.cpp: In member function 'void NODE::init()':
circle_selection.cpp:47:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
47 | for(int i=0; i<par.size(); i++)par[i]=i;
| ~^~~~~~~~~~~
circle_selection.cpp: In function 'int main()':
circle_selection.cpp:73:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
73 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
circle_selection.cpp:75:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
75 | scanf("%d %d %d", &arr[i].F.F, &arr[i].F.S, &arr[i].S.F);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
77 ms |
113016 KB |
Output is correct |
2 |
Correct |
79 ms |
113016 KB |
Output is correct |
3 |
Correct |
76 ms |
113016 KB |
Output is correct |
4 |
Correct |
75 ms |
113036 KB |
Output is correct |
5 |
Correct |
79 ms |
113212 KB |
Output is correct |
6 |
Correct |
76 ms |
113144 KB |
Output is correct |
7 |
Correct |
76 ms |
113144 KB |
Output is correct |
8 |
Correct |
76 ms |
113184 KB |
Output is correct |
9 |
Correct |
75 ms |
113144 KB |
Output is correct |
10 |
Correct |
78 ms |
113144 KB |
Output is correct |
11 |
Correct |
76 ms |
113180 KB |
Output is correct |
12 |
Correct |
76 ms |
113104 KB |
Output is correct |
13 |
Correct |
76 ms |
113180 KB |
Output is correct |
14 |
Correct |
76 ms |
113144 KB |
Output is correct |
15 |
Correct |
77 ms |
113148 KB |
Output is correct |
16 |
Correct |
80 ms |
113784 KB |
Output is correct |
17 |
Correct |
92 ms |
113964 KB |
Output is correct |
18 |
Correct |
80 ms |
113784 KB |
Output is correct |
19 |
Correct |
107 ms |
118516 KB |
Output is correct |
20 |
Correct |
104 ms |
118388 KB |
Output is correct |
21 |
Correct |
109 ms |
118388 KB |
Output is correct |
22 |
Correct |
109 ms |
118392 KB |
Output is correct |
23 |
Correct |
110 ms |
118384 KB |
Output is correct |
24 |
Correct |
106 ms |
118388 KB |
Output is correct |
25 |
Correct |
110 ms |
118380 KB |
Output is correct |
26 |
Correct |
112 ms |
118388 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3103 ms |
525096 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
77 ms |
113016 KB |
Output is correct |
2 |
Correct |
1228 ms |
231768 KB |
Output is correct |
3 |
Execution timed out |
3096 ms |
535044 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3107 ms |
529888 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
77 ms |
113016 KB |
Output is correct |
2 |
Correct |
79 ms |
113016 KB |
Output is correct |
3 |
Correct |
76 ms |
113016 KB |
Output is correct |
4 |
Correct |
75 ms |
113036 KB |
Output is correct |
5 |
Correct |
79 ms |
113212 KB |
Output is correct |
6 |
Correct |
76 ms |
113144 KB |
Output is correct |
7 |
Correct |
76 ms |
113144 KB |
Output is correct |
8 |
Correct |
76 ms |
113184 KB |
Output is correct |
9 |
Correct |
75 ms |
113144 KB |
Output is correct |
10 |
Correct |
78 ms |
113144 KB |
Output is correct |
11 |
Correct |
76 ms |
113180 KB |
Output is correct |
12 |
Correct |
76 ms |
113104 KB |
Output is correct |
13 |
Correct |
76 ms |
113180 KB |
Output is correct |
14 |
Correct |
76 ms |
113144 KB |
Output is correct |
15 |
Correct |
77 ms |
113148 KB |
Output is correct |
16 |
Correct |
80 ms |
113784 KB |
Output is correct |
17 |
Correct |
92 ms |
113964 KB |
Output is correct |
18 |
Correct |
80 ms |
113784 KB |
Output is correct |
19 |
Correct |
107 ms |
118516 KB |
Output is correct |
20 |
Correct |
104 ms |
118388 KB |
Output is correct |
21 |
Correct |
109 ms |
118388 KB |
Output is correct |
22 |
Correct |
109 ms |
118392 KB |
Output is correct |
23 |
Correct |
110 ms |
118384 KB |
Output is correct |
24 |
Correct |
106 ms |
118388 KB |
Output is correct |
25 |
Correct |
110 ms |
118380 KB |
Output is correct |
26 |
Correct |
112 ms |
118388 KB |
Output is correct |
27 |
Correct |
154 ms |
124144 KB |
Output is correct |
28 |
Correct |
154 ms |
124144 KB |
Output is correct |
29 |
Correct |
160 ms |
124144 KB |
Output is correct |
30 |
Correct |
159 ms |
124272 KB |
Output is correct |
31 |
Correct |
164 ms |
124396 KB |
Output is correct |
32 |
Correct |
152 ms |
124272 KB |
Output is correct |
33 |
Correct |
1091 ms |
231160 KB |
Output is correct |
34 |
Correct |
1136 ms |
233296 KB |
Output is correct |
35 |
Correct |
1160 ms |
233432 KB |
Output is correct |
36 |
Correct |
1166 ms |
234004 KB |
Output is correct |
37 |
Correct |
1169 ms |
234072 KB |
Output is correct |
38 |
Correct |
1177 ms |
234020 KB |
Output is correct |
39 |
Correct |
662 ms |
176984 KB |
Output is correct |
40 |
Correct |
658 ms |
176604 KB |
Output is correct |
41 |
Correct |
656 ms |
176836 KB |
Output is correct |
42 |
Correct |
658 ms |
181436 KB |
Output is correct |
43 |
Correct |
1109 ms |
233820 KB |
Output is correct |
44 |
Correct |
1104 ms |
234064 KB |
Output is correct |
45 |
Correct |
1088 ms |
233944 KB |
Output is correct |
46 |
Correct |
1082 ms |
233952 KB |
Output is correct |
47 |
Correct |
1085 ms |
233692 KB |
Output is correct |
48 |
Correct |
1105 ms |
233944 KB |
Output is correct |
49 |
Correct |
1093 ms |
234204 KB |
Output is correct |
50 |
Correct |
1110 ms |
233940 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
77 ms |
113016 KB |
Output is correct |
2 |
Correct |
79 ms |
113016 KB |
Output is correct |
3 |
Correct |
76 ms |
113016 KB |
Output is correct |
4 |
Correct |
75 ms |
113036 KB |
Output is correct |
5 |
Correct |
79 ms |
113212 KB |
Output is correct |
6 |
Correct |
76 ms |
113144 KB |
Output is correct |
7 |
Correct |
76 ms |
113144 KB |
Output is correct |
8 |
Correct |
76 ms |
113184 KB |
Output is correct |
9 |
Correct |
75 ms |
113144 KB |
Output is correct |
10 |
Correct |
78 ms |
113144 KB |
Output is correct |
11 |
Correct |
76 ms |
113180 KB |
Output is correct |
12 |
Correct |
76 ms |
113104 KB |
Output is correct |
13 |
Correct |
76 ms |
113180 KB |
Output is correct |
14 |
Correct |
76 ms |
113144 KB |
Output is correct |
15 |
Correct |
77 ms |
113148 KB |
Output is correct |
16 |
Correct |
80 ms |
113784 KB |
Output is correct |
17 |
Correct |
92 ms |
113964 KB |
Output is correct |
18 |
Correct |
80 ms |
113784 KB |
Output is correct |
19 |
Correct |
107 ms |
118516 KB |
Output is correct |
20 |
Correct |
104 ms |
118388 KB |
Output is correct |
21 |
Correct |
109 ms |
118388 KB |
Output is correct |
22 |
Correct |
109 ms |
118392 KB |
Output is correct |
23 |
Correct |
110 ms |
118384 KB |
Output is correct |
24 |
Correct |
106 ms |
118388 KB |
Output is correct |
25 |
Correct |
110 ms |
118380 KB |
Output is correct |
26 |
Correct |
112 ms |
118388 KB |
Output is correct |
27 |
Execution timed out |
3103 ms |
525096 KB |
Time limit exceeded |
28 |
Halted |
0 ms |
0 KB |
- |