#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<pair<int,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].emplace_back(i,idxs[it].size()+1);
else it=mp.size(),idxs[it].emplace_back(i,idxs[it].size()+1);
// 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>=100 || killcount>=8000){
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;
int prv=-1;
for(int ix=0;ix<idxs[it->second].size();){
// for(auto &i:idxs[it->second]){
auto i=idxs[it->second][ix];
if(1ll*(c[i.first].x-c[masterPtr].x)*(c[i.first].x-c[masterPtr].x)+1ll*(c[i.first].y-c[masterPtr].y)*(c[i.first].y-c[masterPtr].y)<=1ll*(c[masterPtr].r+c[i.first].r)*(c[masterPtr].r+c[i.first].r)){
ans[c[i.first].i]=c[masterPtr].i;
if(c[i.first].i!=c[masterPtr].i)c[i.first].i=0;
++killcount;
if(prv!=-1)idxs[it->second][prv].second=i.second;
}
prv=ix;
ix=i.second;
}
}
}
c[masterPtr].i=0;
}
for(int i=1;i<=n;++i){
printf("%d ",ans[i]);
}
}
Compilation message
circle_selection.cpp: In function 'int main()':
circle_selection.cpp:81:32: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int ix=0;ix<idxs[it->second].size();){
~~^~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
7416 KB |
Output is correct |
2 |
Correct |
7 ms |
7416 KB |
Output is correct |
3 |
Correct |
9 ms |
7416 KB |
Output is correct |
4 |
Correct |
9 ms |
7468 KB |
Output is correct |
5 |
Correct |
8 ms |
7524 KB |
Output is correct |
6 |
Correct |
8 ms |
7524 KB |
Output is correct |
7 |
Correct |
8 ms |
7732 KB |
Output is correct |
8 |
Correct |
7 ms |
7732 KB |
Output is correct |
9 |
Correct |
8 ms |
7732 KB |
Output is correct |
10 |
Correct |
9 ms |
7732 KB |
Output is correct |
11 |
Correct |
7 ms |
7732 KB |
Output is correct |
12 |
Correct |
8 ms |
7732 KB |
Output is correct |
13 |
Correct |
9 ms |
7732 KB |
Output is correct |
14 |
Correct |
8 ms |
7732 KB |
Output is correct |
15 |
Correct |
7 ms |
7732 KB |
Output is correct |
16 |
Correct |
8 ms |
7732 KB |
Output is correct |
17 |
Correct |
8 ms |
7732 KB |
Output is correct |
18 |
Correct |
8 ms |
7732 KB |
Output is correct |
19 |
Correct |
10 ms |
7808 KB |
Output is correct |
20 |
Correct |
10 ms |
7840 KB |
Output is correct |
21 |
Correct |
10 ms |
7840 KB |
Output is correct |
22 |
Correct |
17 ms |
8204 KB |
Output is correct |
23 |
Correct |
17 ms |
8292 KB |
Output is correct |
24 |
Correct |
18 ms |
8292 KB |
Output is correct |
25 |
Correct |
18 ms |
8292 KB |
Output is correct |
26 |
Correct |
18 ms |
8292 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
135 ms |
18080 KB |
Output is correct |
2 |
Correct |
144 ms |
19664 KB |
Output is correct |
3 |
Correct |
144 ms |
19664 KB |
Output is correct |
4 |
Correct |
144 ms |
19664 KB |
Output is correct |
5 |
Correct |
686 ms |
20284 KB |
Output is correct |
6 |
Correct |
2426 ms |
32172 KB |
Output is correct |
7 |
Correct |
724 ms |
32172 KB |
Output is correct |
8 |
Correct |
1031 ms |
32172 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
32172 KB |
Output is correct |
2 |
Correct |
435 ms |
32172 KB |
Output is correct |
3 |
Execution timed out |
3048 ms |
40596 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3071 ms |
40596 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
7416 KB |
Output is correct |
2 |
Correct |
7 ms |
7416 KB |
Output is correct |
3 |
Correct |
9 ms |
7416 KB |
Output is correct |
4 |
Correct |
9 ms |
7468 KB |
Output is correct |
5 |
Correct |
8 ms |
7524 KB |
Output is correct |
6 |
Correct |
8 ms |
7524 KB |
Output is correct |
7 |
Correct |
8 ms |
7732 KB |
Output is correct |
8 |
Correct |
7 ms |
7732 KB |
Output is correct |
9 |
Correct |
8 ms |
7732 KB |
Output is correct |
10 |
Correct |
9 ms |
7732 KB |
Output is correct |
11 |
Correct |
7 ms |
7732 KB |
Output is correct |
12 |
Correct |
8 ms |
7732 KB |
Output is correct |
13 |
Correct |
9 ms |
7732 KB |
Output is correct |
14 |
Correct |
8 ms |
7732 KB |
Output is correct |
15 |
Correct |
7 ms |
7732 KB |
Output is correct |
16 |
Correct |
8 ms |
7732 KB |
Output is correct |
17 |
Correct |
8 ms |
7732 KB |
Output is correct |
18 |
Correct |
8 ms |
7732 KB |
Output is correct |
19 |
Correct |
10 ms |
7808 KB |
Output is correct |
20 |
Correct |
10 ms |
7840 KB |
Output is correct |
21 |
Correct |
10 ms |
7840 KB |
Output is correct |
22 |
Correct |
17 ms |
8204 KB |
Output is correct |
23 |
Correct |
17 ms |
8292 KB |
Output is correct |
24 |
Correct |
18 ms |
8292 KB |
Output is correct |
25 |
Correct |
18 ms |
8292 KB |
Output is correct |
26 |
Correct |
18 ms |
8292 KB |
Output is correct |
27 |
Correct |
15 ms |
40596 KB |
Output is correct |
28 |
Correct |
13 ms |
40596 KB |
Output is correct |
29 |
Correct |
12 ms |
40596 KB |
Output is correct |
30 |
Correct |
29 ms |
40596 KB |
Output is correct |
31 |
Correct |
27 ms |
40596 KB |
Output is correct |
32 |
Correct |
26 ms |
40596 KB |
Output is correct |
33 |
Correct |
52 ms |
40596 KB |
Output is correct |
34 |
Correct |
51 ms |
40596 KB |
Output is correct |
35 |
Correct |
55 ms |
40596 KB |
Output is correct |
36 |
Correct |
419 ms |
40596 KB |
Output is correct |
37 |
Correct |
427 ms |
40596 KB |
Output is correct |
38 |
Correct |
462 ms |
40596 KB |
Output is correct |
39 |
Correct |
396 ms |
40596 KB |
Output is correct |
40 |
Correct |
404 ms |
40596 KB |
Output is correct |
41 |
Correct |
364 ms |
40596 KB |
Output is correct |
42 |
Correct |
378 ms |
40596 KB |
Output is correct |
43 |
Correct |
498 ms |
40596 KB |
Output is correct |
44 |
Correct |
503 ms |
40596 KB |
Output is correct |
45 |
Correct |
380 ms |
40596 KB |
Output is correct |
46 |
Correct |
419 ms |
40596 KB |
Output is correct |
47 |
Correct |
360 ms |
40596 KB |
Output is correct |
48 |
Correct |
389 ms |
40596 KB |
Output is correct |
49 |
Correct |
506 ms |
40596 KB |
Output is correct |
50 |
Correct |
415 ms |
40596 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
7416 KB |
Output is correct |
2 |
Correct |
7 ms |
7416 KB |
Output is correct |
3 |
Correct |
9 ms |
7416 KB |
Output is correct |
4 |
Correct |
9 ms |
7468 KB |
Output is correct |
5 |
Correct |
8 ms |
7524 KB |
Output is correct |
6 |
Correct |
8 ms |
7524 KB |
Output is correct |
7 |
Correct |
8 ms |
7732 KB |
Output is correct |
8 |
Correct |
7 ms |
7732 KB |
Output is correct |
9 |
Correct |
8 ms |
7732 KB |
Output is correct |
10 |
Correct |
9 ms |
7732 KB |
Output is correct |
11 |
Correct |
7 ms |
7732 KB |
Output is correct |
12 |
Correct |
8 ms |
7732 KB |
Output is correct |
13 |
Correct |
9 ms |
7732 KB |
Output is correct |
14 |
Correct |
8 ms |
7732 KB |
Output is correct |
15 |
Correct |
7 ms |
7732 KB |
Output is correct |
16 |
Correct |
8 ms |
7732 KB |
Output is correct |
17 |
Correct |
8 ms |
7732 KB |
Output is correct |
18 |
Correct |
8 ms |
7732 KB |
Output is correct |
19 |
Correct |
10 ms |
7808 KB |
Output is correct |
20 |
Correct |
10 ms |
7840 KB |
Output is correct |
21 |
Correct |
10 ms |
7840 KB |
Output is correct |
22 |
Correct |
17 ms |
8204 KB |
Output is correct |
23 |
Correct |
17 ms |
8292 KB |
Output is correct |
24 |
Correct |
18 ms |
8292 KB |
Output is correct |
25 |
Correct |
18 ms |
8292 KB |
Output is correct |
26 |
Correct |
18 ms |
8292 KB |
Output is correct |
27 |
Correct |
135 ms |
18080 KB |
Output is correct |
28 |
Correct |
144 ms |
19664 KB |
Output is correct |
29 |
Correct |
144 ms |
19664 KB |
Output is correct |
30 |
Correct |
144 ms |
19664 KB |
Output is correct |
31 |
Correct |
686 ms |
20284 KB |
Output is correct |
32 |
Correct |
2426 ms |
32172 KB |
Output is correct |
33 |
Correct |
724 ms |
32172 KB |
Output is correct |
34 |
Correct |
1031 ms |
32172 KB |
Output is correct |
35 |
Correct |
9 ms |
32172 KB |
Output is correct |
36 |
Correct |
435 ms |
32172 KB |
Output is correct |
37 |
Execution timed out |
3048 ms |
40596 KB |
Time limit exceeded |
38 |
Halted |
0 ms |
0 KB |
- |