#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int MX=300010, inf=2e9;
struct CIRCLE {
int x, y, r, idx, kill;
} C[MX];
inline ll sq(ll x){ return x*x; }
inline ll dist(int a, int b){
return sq(C[a].x-C[b].x)+sq(C[a].y-C[b].y);
}
inline bool hit(int a, int b){
return dist(a,b)<=sq(C[a].r+C[b].r);
}
int n;
void input(){
cin>>n;
for(int i=1; i<=n; i++){
int x, y, r;
cin>>x>>y>>r;
C[i]={x,y,r,i,0};
}
}
vector<vector<vi>> G;
ll t=1<<30;
// [-t, 0), [0, t)
inline int sect(int idx, int x0, int y0){
// 1 3
// 0 2
int x=C[idx].x, y=C[idx].y;
if(x<x0)
if(y<y0) return 0;
else return 1;
else
if(y<y0) return 2;
else return 3;
}
inline int range(ll x){
if(x>0) return x/t;
return -((-x+t-1)/t);
}
inline int xrange(const vi &cell){
return range(C[cell.front()].x);
}
inline int yrange(const vi &cell){
return range(C[cell.front()].y);
}
inline int xrange(const vector<vi> &X){
return xrange(X.front());
}
void init_grid(){
vi V[4];
for(int i=1; i<=n; i++){
V[sect(i,0,0)].push_back(i);
}
vector<vi> X[2];
for(int k=0; k<4; k++)
if(!V[k].empty())
X[k/2].push_back(V[k]);
if(!X[0].empty()) G.push_back(X[0]);
if(!X[1].empty()) G.push_back(X[1]);
}
void resize_grid(){
vector<vector<vi>> tmp;
for(auto &X:G){
vector<vi> newX[2];
for(vi &cell:X){
vi V[4];
int x=xrange(cell)*t + t/2;
int y=yrange(cell)*t + t/2;
for(int idx:cell){
if(C[idx].kill!=0) continue;
V[sect(idx,x,y)].push_back(idx);
}
for(int k=0; k<4; k++)
if(!V[k].empty())
newX[k/2].push_back(V[k]);
}
if(!newX[0].empty()) tmp.push_back(newX[0]);
if(!newX[1].empty()) tmp.push_back(newX[1]);
}
// slow!!!
G=tmp;
t/=2;
}
void process(const vi &cell, int killer){
// cell을 업데이트 안해도 되나?
for(int killed:cell)
if(C[killed].kill==0 && hit(killed, killer))
C[killed].kill=killer;
}
void kill(int idx){
while(C[idx].r*2<t){
resize_grid();
}
int x=C[idx].x, y=C[idx].y;
ll lx=range(x)-2, hx=range(x)+3;
ll ly=range(y)-2, hy=range(y)+3;
int n1=G.size();
int s1=0, e1=n1-1;
while(s1<e1){
int m1=(s1+e1)/2;
if(xrange(G[m1])<lx) s1=m1+1;
else e1=m1;
}
int pos=s1;
while(pos<min(n1,s1+5) && lx<=xrange(G[pos]) && xrange(G[pos])<=hx){
vector<vi> &X=G[pos];
int n2=X.size();
int s2=0, e2=n2-1;
while(s2<e2){
int m2=(s2+e2)/2;
if(yrange(X[m2])<ly) s2=m2+1;
else e2=m2;
}
while(s2<n2 && ly<=yrange(X[s2]) && yrange(X[s2])<=hy){
process(X[s2], idx);
s2++;
}
pos++;
}
}
void solve(){
CIRCLE D[MX];
for(int i=1; i<=n; i++) D[i]=C[i];
sort(D+1, D+n+1, [](CIRCLE &a, CIRCLE &b){
if(a.r==b.r) return a.idx<b.idx;
return a.r>b.r;
});
for(int i=1; i<=n; i++){
int idx=D[i].idx;
if(C[idx].kill!=0) continue;
kill(idx);
}
}
int main(){
ios::sync_with_stdio(0); cin.tie(0);
input();
init_grid();
solve();
for(int i=1; i<=n; i++) cout<<C[i].kill<<' ';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
436 KB |
Output is correct |
4 |
Correct |
2 ms |
492 KB |
Output is correct |
5 |
Correct |
2 ms |
536 KB |
Output is correct |
6 |
Correct |
2 ms |
556 KB |
Output is correct |
7 |
Correct |
2 ms |
556 KB |
Output is correct |
8 |
Correct |
2 ms |
556 KB |
Output is correct |
9 |
Correct |
2 ms |
656 KB |
Output is correct |
10 |
Correct |
2 ms |
656 KB |
Output is correct |
11 |
Correct |
3 ms |
656 KB |
Output is correct |
12 |
Correct |
2 ms |
656 KB |
Output is correct |
13 |
Correct |
3 ms |
656 KB |
Output is correct |
14 |
Correct |
3 ms |
656 KB |
Output is correct |
15 |
Correct |
2 ms |
656 KB |
Output is correct |
16 |
Correct |
2 ms |
688 KB |
Output is correct |
17 |
Correct |
2 ms |
688 KB |
Output is correct |
18 |
Correct |
3 ms |
752 KB |
Output is correct |
19 |
Correct |
5 ms |
892 KB |
Output is correct |
20 |
Correct |
5 ms |
892 KB |
Output is correct |
21 |
Correct |
5 ms |
924 KB |
Output is correct |
22 |
Correct |
26 ms |
1928 KB |
Output is correct |
23 |
Correct |
26 ms |
1928 KB |
Output is correct |
24 |
Correct |
28 ms |
1964 KB |
Output is correct |
25 |
Correct |
34 ms |
2220 KB |
Output is correct |
26 |
Correct |
30 ms |
2220 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
238 ms |
15944 KB |
Output is correct |
2 |
Correct |
227 ms |
17188 KB |
Output is correct |
3 |
Correct |
197 ms |
17560 KB |
Output is correct |
4 |
Correct |
247 ms |
17560 KB |
Output is correct |
5 |
Correct |
399 ms |
18776 KB |
Output is correct |
6 |
Correct |
1192 ms |
38232 KB |
Output is correct |
7 |
Correct |
390 ms |
38232 KB |
Output is correct |
8 |
Correct |
621 ms |
38232 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
38232 KB |
Output is correct |
2 |
Correct |
818 ms |
38232 KB |
Output is correct |
3 |
Correct |
2686 ms |
63220 KB |
Output is correct |
4 |
Correct |
2531 ms |
63364 KB |
Output is correct |
5 |
Correct |
1702 ms |
63364 KB |
Output is correct |
6 |
Correct |
818 ms |
63364 KB |
Output is correct |
7 |
Correct |
360 ms |
63364 KB |
Output is correct |
8 |
Correct |
96 ms |
63364 KB |
Output is correct |
9 |
Correct |
2415 ms |
63364 KB |
Output is correct |
10 |
Correct |
1514 ms |
63364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2634 ms |
68652 KB |
Output is correct |
2 |
Execution timed out |
3076 ms |
93996 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
436 KB |
Output is correct |
4 |
Correct |
2 ms |
492 KB |
Output is correct |
5 |
Correct |
2 ms |
536 KB |
Output is correct |
6 |
Correct |
2 ms |
556 KB |
Output is correct |
7 |
Correct |
2 ms |
556 KB |
Output is correct |
8 |
Correct |
2 ms |
556 KB |
Output is correct |
9 |
Correct |
2 ms |
656 KB |
Output is correct |
10 |
Correct |
2 ms |
656 KB |
Output is correct |
11 |
Correct |
3 ms |
656 KB |
Output is correct |
12 |
Correct |
2 ms |
656 KB |
Output is correct |
13 |
Correct |
3 ms |
656 KB |
Output is correct |
14 |
Correct |
3 ms |
656 KB |
Output is correct |
15 |
Correct |
2 ms |
656 KB |
Output is correct |
16 |
Correct |
2 ms |
688 KB |
Output is correct |
17 |
Correct |
2 ms |
688 KB |
Output is correct |
18 |
Correct |
3 ms |
752 KB |
Output is correct |
19 |
Correct |
5 ms |
892 KB |
Output is correct |
20 |
Correct |
5 ms |
892 KB |
Output is correct |
21 |
Correct |
5 ms |
924 KB |
Output is correct |
22 |
Correct |
26 ms |
1928 KB |
Output is correct |
23 |
Correct |
26 ms |
1928 KB |
Output is correct |
24 |
Correct |
28 ms |
1964 KB |
Output is correct |
25 |
Correct |
34 ms |
2220 KB |
Output is correct |
26 |
Correct |
30 ms |
2220 KB |
Output is correct |
27 |
Correct |
15 ms |
93996 KB |
Output is correct |
28 |
Correct |
9 ms |
93996 KB |
Output is correct |
29 |
Correct |
11 ms |
93996 KB |
Output is correct |
30 |
Correct |
63 ms |
93996 KB |
Output is correct |
31 |
Correct |
54 ms |
93996 KB |
Output is correct |
32 |
Correct |
59 ms |
93996 KB |
Output is correct |
33 |
Correct |
71 ms |
93996 KB |
Output is correct |
34 |
Correct |
126 ms |
93996 KB |
Output is correct |
35 |
Correct |
73 ms |
93996 KB |
Output is correct |
36 |
Correct |
788 ms |
93996 KB |
Output is correct |
37 |
Correct |
836 ms |
93996 KB |
Output is correct |
38 |
Correct |
812 ms |
93996 KB |
Output is correct |
39 |
Correct |
494 ms |
93996 KB |
Output is correct |
40 |
Correct |
309 ms |
93996 KB |
Output is correct |
41 |
Correct |
309 ms |
93996 KB |
Output is correct |
42 |
Correct |
214 ms |
93996 KB |
Output is correct |
43 |
Correct |
559 ms |
93996 KB |
Output is correct |
44 |
Correct |
620 ms |
93996 KB |
Output is correct |
45 |
Correct |
572 ms |
93996 KB |
Output is correct |
46 |
Correct |
642 ms |
93996 KB |
Output is correct |
47 |
Correct |
715 ms |
93996 KB |
Output is correct |
48 |
Correct |
759 ms |
93996 KB |
Output is correct |
49 |
Correct |
675 ms |
93996 KB |
Output is correct |
50 |
Correct |
784 ms |
93996 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
436 KB |
Output is correct |
4 |
Correct |
2 ms |
492 KB |
Output is correct |
5 |
Correct |
2 ms |
536 KB |
Output is correct |
6 |
Correct |
2 ms |
556 KB |
Output is correct |
7 |
Correct |
2 ms |
556 KB |
Output is correct |
8 |
Correct |
2 ms |
556 KB |
Output is correct |
9 |
Correct |
2 ms |
656 KB |
Output is correct |
10 |
Correct |
2 ms |
656 KB |
Output is correct |
11 |
Correct |
3 ms |
656 KB |
Output is correct |
12 |
Correct |
2 ms |
656 KB |
Output is correct |
13 |
Correct |
3 ms |
656 KB |
Output is correct |
14 |
Correct |
3 ms |
656 KB |
Output is correct |
15 |
Correct |
2 ms |
656 KB |
Output is correct |
16 |
Correct |
2 ms |
688 KB |
Output is correct |
17 |
Correct |
2 ms |
688 KB |
Output is correct |
18 |
Correct |
3 ms |
752 KB |
Output is correct |
19 |
Correct |
5 ms |
892 KB |
Output is correct |
20 |
Correct |
5 ms |
892 KB |
Output is correct |
21 |
Correct |
5 ms |
924 KB |
Output is correct |
22 |
Correct |
26 ms |
1928 KB |
Output is correct |
23 |
Correct |
26 ms |
1928 KB |
Output is correct |
24 |
Correct |
28 ms |
1964 KB |
Output is correct |
25 |
Correct |
34 ms |
2220 KB |
Output is correct |
26 |
Correct |
30 ms |
2220 KB |
Output is correct |
27 |
Correct |
238 ms |
15944 KB |
Output is correct |
28 |
Correct |
227 ms |
17188 KB |
Output is correct |
29 |
Correct |
197 ms |
17560 KB |
Output is correct |
30 |
Correct |
247 ms |
17560 KB |
Output is correct |
31 |
Correct |
399 ms |
18776 KB |
Output is correct |
32 |
Correct |
1192 ms |
38232 KB |
Output is correct |
33 |
Correct |
390 ms |
38232 KB |
Output is correct |
34 |
Correct |
621 ms |
38232 KB |
Output is correct |
35 |
Correct |
3 ms |
38232 KB |
Output is correct |
36 |
Correct |
818 ms |
38232 KB |
Output is correct |
37 |
Correct |
2686 ms |
63220 KB |
Output is correct |
38 |
Correct |
2531 ms |
63364 KB |
Output is correct |
39 |
Correct |
1702 ms |
63364 KB |
Output is correct |
40 |
Correct |
818 ms |
63364 KB |
Output is correct |
41 |
Correct |
360 ms |
63364 KB |
Output is correct |
42 |
Correct |
96 ms |
63364 KB |
Output is correct |
43 |
Correct |
2415 ms |
63364 KB |
Output is correct |
44 |
Correct |
1514 ms |
63364 KB |
Output is correct |
45 |
Correct |
2634 ms |
68652 KB |
Output is correct |
46 |
Execution timed out |
3076 ms |
93996 KB |
Time limit exceeded |
47 |
Halted |
0 ms |
0 KB |
- |