#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx,tune=native")
#include<cstdio>
#include<unordered_map>
#include<vector>
#include<utility>
#include<algorithm>
using namespace std;
int n,pos[300005],ans[300005];
struct circle{
int x,y,r,i;
} c[300005];
namespace std {
template<> struct hash<pair<int,int>> {
long long operator()(const pair<int,int> &a) const {
return 1ll*a.first*1000000009+a.second;
}
};
}
unordered_map<pair<int,int>,int> mp;
vector<int> idxs[300005];
int rit(){
char c; int x=0; bool mi=0;
while((c=getchar_unlocked())){ if(c=='-' || (c>='0' && c<='9'))break; }
if(c=='-')mi=1;
else x=c-'0';
while((c=getchar_unlocked())){ if(c<'0' || c>'9')break; x=x*10+(c&15); }
return mi?-x:x;
}
int main(){
n=rit();
for(int i=0;i<n;++i){
c[i].x=rit(),c[i].y=rit(),c[i].r=rit();
c[i].i=i+1;
}
sort(c,c+n,[](const circle &a,const circle &b){ return a.r==b.r?a.i<b.i:a.r>b.r; });
// for(int i=0;i<n;++i)pos[c[i].i]=i;
int masterPtr=0;
int D=c[0].r,killcount=0;
auto buildGraph=[&](){
for(int i=1;i<=int(mp.size());++i)idxs[i].clear();
mp.clear();
D=c[masterPtr].r;
killcount=0;
for(int i=masterPtr;i<n;++i){
if(c[i].i==0)continue;
pair<int,int> pos(c[i].x/D,c[i].y/D);
int &it=mp[pos];
if(it)idxs[it].push_back(i);
else idxs[(it=mp.size())].push_back(i);
// cout<<"insert "<<i<<" into "<<it<<" , pos: "<<pos.first<<" , "<<pos.second<<endl;
}
};
buildGraph();
while(masterPtr<n){
while(masterPtr<n && c[masterPtr].i==0)++masterPtr;
if(masterPtr>=n)break;
// cout<<"now masterPtr: "<<masterPtr<<" circle is "<<c[masterPtr].i<<endl;
// cout<<"circle position: "<<c[masterPtr].x<<" "<<c[masterPtr].y<<endl;
if(D/c[masterPtr].r>=7 && killcount>=1000){
buildGraph();
// cout<<"map contains: "<<endl;
// for(auto p:mp)cout<<"[("<<p.first.first<<" , "<<p.first.second<<") : "<<p.second<<"] ";
// cout<<endl;
}
pair<int,int> pos(c[masterPtr].x/D,c[masterPtr].y/D);
// cout<<"base position: "<<pos.first<<" "<<pos.second<<endl;
for(int dx=-2;dx<=2;++dx){
for(int dy=-2;dy<=2;++dy){
auto it=mp.find(make_pair(pos.first+dx,pos.second+dy));
if(it==mp.end())continue;
// cout<<"it's not the end: "<<it->second<<endl;
for(int i:idxs[it->second]){
if(c[i].i==0)continue;
if(1ll*(c[i].x-c[masterPtr].x)*(c[i].x-c[masterPtr].x)+1ll*(c[i].y-c[masterPtr].y)*(c[i].y-c[masterPtr].y)>1ll*(c[masterPtr].r+c[i].r)*(c[masterPtr].r+c[i].r))continue;
ans[c[i].i]=c[masterPtr].i;
// cout<<"killed "<<c[i].i<<", killer: "<<c[masterPtr].i<<endl;
if(c[i].i!=c[masterPtr].i)c[i].i=0;
++killcount;
}
}
}
c[masterPtr].i=0;
}
for(int i=1;i<=n;++i){
printf("%d ",ans[i]);
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
7292 KB |
Output is correct |
2 |
Correct |
8 ms |
7400 KB |
Output is correct |
3 |
Correct |
7 ms |
7604 KB |
Output is correct |
4 |
Correct |
8 ms |
7604 KB |
Output is correct |
5 |
Correct |
8 ms |
7604 KB |
Output is correct |
6 |
Correct |
7 ms |
7604 KB |
Output is correct |
7 |
Correct |
8 ms |
7604 KB |
Output is correct |
8 |
Correct |
7 ms |
7604 KB |
Output is correct |
9 |
Correct |
8 ms |
7604 KB |
Output is correct |
10 |
Correct |
9 ms |
7660 KB |
Output is correct |
11 |
Correct |
8 ms |
7660 KB |
Output is correct |
12 |
Correct |
8 ms |
7660 KB |
Output is correct |
13 |
Correct |
8 ms |
7680 KB |
Output is correct |
14 |
Correct |
9 ms |
7680 KB |
Output is correct |
15 |
Correct |
9 ms |
7680 KB |
Output is correct |
16 |
Correct |
8 ms |
7680 KB |
Output is correct |
17 |
Correct |
8 ms |
7680 KB |
Output is correct |
18 |
Correct |
8 ms |
7680 KB |
Output is correct |
19 |
Correct |
10 ms |
7808 KB |
Output is correct |
20 |
Correct |
12 ms |
7808 KB |
Output is correct |
21 |
Correct |
10 ms |
7824 KB |
Output is correct |
22 |
Correct |
18 ms |
8224 KB |
Output is correct |
23 |
Correct |
18 ms |
8240 KB |
Output is correct |
24 |
Correct |
18 ms |
8240 KB |
Output is correct |
25 |
Correct |
17 ms |
8240 KB |
Output is correct |
26 |
Correct |
18 ms |
8240 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
138 ms |
17056 KB |
Output is correct |
2 |
Correct |
143 ms |
17272 KB |
Output is correct |
3 |
Correct |
143 ms |
17272 KB |
Output is correct |
4 |
Correct |
137 ms |
17272 KB |
Output is correct |
5 |
Correct |
180 ms |
17984 KB |
Output is correct |
6 |
Correct |
724 ms |
28828 KB |
Output is correct |
7 |
Correct |
256 ms |
28828 KB |
Output is correct |
8 |
Correct |
362 ms |
28828 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
28828 KB |
Output is correct |
2 |
Correct |
444 ms |
28828 KB |
Output is correct |
3 |
Correct |
1456 ms |
42408 KB |
Output is correct |
4 |
Correct |
1578 ms |
42572 KB |
Output is correct |
5 |
Correct |
1175 ms |
42572 KB |
Output is correct |
6 |
Correct |
482 ms |
42572 KB |
Output is correct |
7 |
Correct |
250 ms |
42572 KB |
Output is correct |
8 |
Correct |
39 ms |
42572 KB |
Output is correct |
9 |
Correct |
1453 ms |
42572 KB |
Output is correct |
10 |
Correct |
1187 ms |
42572 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1817 ms |
42628 KB |
Output is correct |
2 |
Correct |
1515 ms |
42628 KB |
Output is correct |
3 |
Correct |
545 ms |
42628 KB |
Output is correct |
4 |
Correct |
1624 ms |
42700 KB |
Output is correct |
5 |
Correct |
1653 ms |
42700 KB |
Output is correct |
6 |
Correct |
212 ms |
42700 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
7292 KB |
Output is correct |
2 |
Correct |
8 ms |
7400 KB |
Output is correct |
3 |
Correct |
7 ms |
7604 KB |
Output is correct |
4 |
Correct |
8 ms |
7604 KB |
Output is correct |
5 |
Correct |
8 ms |
7604 KB |
Output is correct |
6 |
Correct |
7 ms |
7604 KB |
Output is correct |
7 |
Correct |
8 ms |
7604 KB |
Output is correct |
8 |
Correct |
7 ms |
7604 KB |
Output is correct |
9 |
Correct |
8 ms |
7604 KB |
Output is correct |
10 |
Correct |
9 ms |
7660 KB |
Output is correct |
11 |
Correct |
8 ms |
7660 KB |
Output is correct |
12 |
Correct |
8 ms |
7660 KB |
Output is correct |
13 |
Correct |
8 ms |
7680 KB |
Output is correct |
14 |
Correct |
9 ms |
7680 KB |
Output is correct |
15 |
Correct |
9 ms |
7680 KB |
Output is correct |
16 |
Correct |
8 ms |
7680 KB |
Output is correct |
17 |
Correct |
8 ms |
7680 KB |
Output is correct |
18 |
Correct |
8 ms |
7680 KB |
Output is correct |
19 |
Correct |
10 ms |
7808 KB |
Output is correct |
20 |
Correct |
12 ms |
7808 KB |
Output is correct |
21 |
Correct |
10 ms |
7824 KB |
Output is correct |
22 |
Correct |
18 ms |
8224 KB |
Output is correct |
23 |
Correct |
18 ms |
8240 KB |
Output is correct |
24 |
Correct |
18 ms |
8240 KB |
Output is correct |
25 |
Correct |
17 ms |
8240 KB |
Output is correct |
26 |
Correct |
18 ms |
8240 KB |
Output is correct |
27 |
Correct |
15 ms |
42700 KB |
Output is correct |
28 |
Correct |
16 ms |
42700 KB |
Output is correct |
29 |
Correct |
12 ms |
42700 KB |
Output is correct |
30 |
Correct |
27 ms |
42700 KB |
Output is correct |
31 |
Correct |
28 ms |
42700 KB |
Output is correct |
32 |
Correct |
28 ms |
42700 KB |
Output is correct |
33 |
Correct |
53 ms |
42700 KB |
Output is correct |
34 |
Correct |
51 ms |
42700 KB |
Output is correct |
35 |
Correct |
53 ms |
42700 KB |
Output is correct |
36 |
Correct |
367 ms |
42700 KB |
Output is correct |
37 |
Correct |
369 ms |
42700 KB |
Output is correct |
38 |
Correct |
398 ms |
42700 KB |
Output is correct |
39 |
Correct |
322 ms |
42700 KB |
Output is correct |
40 |
Correct |
385 ms |
42700 KB |
Output is correct |
41 |
Correct |
373 ms |
42700 KB |
Output is correct |
42 |
Correct |
366 ms |
42700 KB |
Output is correct |
43 |
Correct |
460 ms |
42700 KB |
Output is correct |
44 |
Correct |
416 ms |
42700 KB |
Output is correct |
45 |
Correct |
479 ms |
42700 KB |
Output is correct |
46 |
Correct |
408 ms |
42700 KB |
Output is correct |
47 |
Correct |
313 ms |
42700 KB |
Output is correct |
48 |
Correct |
315 ms |
42700 KB |
Output is correct |
49 |
Correct |
470 ms |
42700 KB |
Output is correct |
50 |
Correct |
507 ms |
42700 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
7292 KB |
Output is correct |
2 |
Correct |
8 ms |
7400 KB |
Output is correct |
3 |
Correct |
7 ms |
7604 KB |
Output is correct |
4 |
Correct |
8 ms |
7604 KB |
Output is correct |
5 |
Correct |
8 ms |
7604 KB |
Output is correct |
6 |
Correct |
7 ms |
7604 KB |
Output is correct |
7 |
Correct |
8 ms |
7604 KB |
Output is correct |
8 |
Correct |
7 ms |
7604 KB |
Output is correct |
9 |
Correct |
8 ms |
7604 KB |
Output is correct |
10 |
Correct |
9 ms |
7660 KB |
Output is correct |
11 |
Correct |
8 ms |
7660 KB |
Output is correct |
12 |
Correct |
8 ms |
7660 KB |
Output is correct |
13 |
Correct |
8 ms |
7680 KB |
Output is correct |
14 |
Correct |
9 ms |
7680 KB |
Output is correct |
15 |
Correct |
9 ms |
7680 KB |
Output is correct |
16 |
Correct |
8 ms |
7680 KB |
Output is correct |
17 |
Correct |
8 ms |
7680 KB |
Output is correct |
18 |
Correct |
8 ms |
7680 KB |
Output is correct |
19 |
Correct |
10 ms |
7808 KB |
Output is correct |
20 |
Correct |
12 ms |
7808 KB |
Output is correct |
21 |
Correct |
10 ms |
7824 KB |
Output is correct |
22 |
Correct |
18 ms |
8224 KB |
Output is correct |
23 |
Correct |
18 ms |
8240 KB |
Output is correct |
24 |
Correct |
18 ms |
8240 KB |
Output is correct |
25 |
Correct |
17 ms |
8240 KB |
Output is correct |
26 |
Correct |
18 ms |
8240 KB |
Output is correct |
27 |
Correct |
138 ms |
17056 KB |
Output is correct |
28 |
Correct |
143 ms |
17272 KB |
Output is correct |
29 |
Correct |
143 ms |
17272 KB |
Output is correct |
30 |
Correct |
137 ms |
17272 KB |
Output is correct |
31 |
Correct |
180 ms |
17984 KB |
Output is correct |
32 |
Correct |
724 ms |
28828 KB |
Output is correct |
33 |
Correct |
256 ms |
28828 KB |
Output is correct |
34 |
Correct |
362 ms |
28828 KB |
Output is correct |
35 |
Correct |
8 ms |
28828 KB |
Output is correct |
36 |
Correct |
444 ms |
28828 KB |
Output is correct |
37 |
Correct |
1456 ms |
42408 KB |
Output is correct |
38 |
Correct |
1578 ms |
42572 KB |
Output is correct |
39 |
Correct |
1175 ms |
42572 KB |
Output is correct |
40 |
Correct |
482 ms |
42572 KB |
Output is correct |
41 |
Correct |
250 ms |
42572 KB |
Output is correct |
42 |
Correct |
39 ms |
42572 KB |
Output is correct |
43 |
Correct |
1453 ms |
42572 KB |
Output is correct |
44 |
Correct |
1187 ms |
42572 KB |
Output is correct |
45 |
Correct |
1817 ms |
42628 KB |
Output is correct |
46 |
Correct |
1515 ms |
42628 KB |
Output is correct |
47 |
Correct |
545 ms |
42628 KB |
Output is correct |
48 |
Correct |
1624 ms |
42700 KB |
Output is correct |
49 |
Correct |
1653 ms |
42700 KB |
Output is correct |
50 |
Correct |
212 ms |
42700 KB |
Output is correct |
51 |
Correct |
15 ms |
42700 KB |
Output is correct |
52 |
Correct |
16 ms |
42700 KB |
Output is correct |
53 |
Correct |
12 ms |
42700 KB |
Output is correct |
54 |
Correct |
27 ms |
42700 KB |
Output is correct |
55 |
Correct |
28 ms |
42700 KB |
Output is correct |
56 |
Correct |
28 ms |
42700 KB |
Output is correct |
57 |
Correct |
53 ms |
42700 KB |
Output is correct |
58 |
Correct |
51 ms |
42700 KB |
Output is correct |
59 |
Correct |
53 ms |
42700 KB |
Output is correct |
60 |
Correct |
367 ms |
42700 KB |
Output is correct |
61 |
Correct |
369 ms |
42700 KB |
Output is correct |
62 |
Correct |
398 ms |
42700 KB |
Output is correct |
63 |
Correct |
322 ms |
42700 KB |
Output is correct |
64 |
Correct |
385 ms |
42700 KB |
Output is correct |
65 |
Correct |
373 ms |
42700 KB |
Output is correct |
66 |
Correct |
366 ms |
42700 KB |
Output is correct |
67 |
Correct |
460 ms |
42700 KB |
Output is correct |
68 |
Correct |
416 ms |
42700 KB |
Output is correct |
69 |
Correct |
479 ms |
42700 KB |
Output is correct |
70 |
Correct |
408 ms |
42700 KB |
Output is correct |
71 |
Correct |
313 ms |
42700 KB |
Output is correct |
72 |
Correct |
315 ms |
42700 KB |
Output is correct |
73 |
Correct |
470 ms |
42700 KB |
Output is correct |
74 |
Correct |
507 ms |
42700 KB |
Output is correct |
75 |
Correct |
166 ms |
42700 KB |
Output is correct |
76 |
Correct |
161 ms |
42700 KB |
Output is correct |
77 |
Correct |
148 ms |
42700 KB |
Output is correct |
78 |
Correct |
134 ms |
42700 KB |
Output is correct |
79 |
Correct |
185 ms |
42700 KB |
Output is correct |
80 |
Correct |
139 ms |
42700 KB |
Output is correct |
81 |
Correct |
1459 ms |
42700 KB |
Output is correct |
82 |
Correct |
1365 ms |
42700 KB |
Output is correct |
83 |
Correct |
1360 ms |
42700 KB |
Output is correct |
84 |
Correct |
1368 ms |
42704 KB |
Output is correct |
85 |
Correct |
1437 ms |
42704 KB |
Output is correct |
86 |
Correct |
1577 ms |
42704 KB |
Output is correct |
87 |
Correct |
1479 ms |
42704 KB |
Output is correct |
88 |
Correct |
1133 ms |
42704 KB |
Output is correct |
89 |
Correct |
1142 ms |
42704 KB |
Output is correct |
90 |
Correct |
1110 ms |
42704 KB |
Output is correct |
91 |
Correct |
1185 ms |
42704 KB |
Output is correct |
92 |
Correct |
1095 ms |
42704 KB |
Output is correct |
93 |
Correct |
1534 ms |
42704 KB |
Output is correct |
94 |
Correct |
1528 ms |
42704 KB |
Output is correct |
95 |
Correct |
1374 ms |
42704 KB |
Output is correct |
96 |
Correct |
1485 ms |
42704 KB |
Output is correct |
97 |
Correct |
1519 ms |
42704 KB |
Output is correct |
98 |
Correct |
947 ms |
42704 KB |
Output is correct |
99 |
Correct |
1418 ms |
42704 KB |
Output is correct |
100 |
Correct |
1449 ms |
42704 KB |
Output is correct |
101 |
Correct |
1065 ms |
42704 KB |
Output is correct |
102 |
Correct |
1499 ms |
42704 KB |
Output is correct |
103 |
Correct |
1376 ms |
42704 KB |
Output is correct |
104 |
Correct |
1390 ms |
42704 KB |
Output is correct |
105 |
Correct |
805 ms |
42704 KB |
Output is correct |
106 |
Correct |
1275 ms |
42704 KB |
Output is correct |
107 |
Correct |
1251 ms |
42704 KB |
Output is correct |
108 |
Correct |
1239 ms |
42704 KB |
Output is correct |
109 |
Correct |
1441 ms |
42704 KB |
Output is correct |
110 |
Correct |
1333 ms |
42704 KB |
Output is correct |
111 |
Correct |
1439 ms |
42704 KB |
Output is correct |
112 |
Correct |
1347 ms |
42704 KB |
Output is correct |
113 |
Correct |
1212 ms |
42704 KB |
Output is correct |
114 |
Correct |
1323 ms |
42704 KB |
Output is correct |
115 |
Correct |
1266 ms |
42704 KB |
Output is correct |
116 |
Correct |
1316 ms |
42704 KB |
Output is correct |