using namespace std;
#include <iostream>
#include <vector>
#include <algorithm>
#define MAXN 300005
typedef long long ll;
typedef pair<ll,ll> pll;
int N,vis[MAXN],ans[MAXN];
// current unit circle length
long long gl = 1e18;
vector<pair<pair<ll,int>,pll>> pts;
vector<ll> xs;
vector<vector<pair<ll,int>>> g;
int get(long long x) {
x /= gl;
return lower_bound(xs.begin(),xs.end(),x) - xs.begin();
}
long long sq(long long x) {
return x * x;
}
bool check(int a,int b) {
return sq(pts[a].second.first - pts[b].second.first) + sq(pts[a].second.second - pts[b].second.second) <= sq(pts[a].first.first + pts[b].first.first);
}
void reconstruct(long long nl) {
// cout << "BEGIN RECONSTRUCTION!" << endl;
gl = nl;
g.clear();
xs.clear();
for(auto [a,b] : pts) {
xs.push_back(b.first / gl);
}
sort(xs.begin(),xs.end());
xs.resize(unique(xs.begin(),xs.end()) - xs.begin());
g = vector<vector<pair<ll,int>>>(xs.size(),vector<pair<ll,int>>());
for(int i = 0;i < N;++i) {
if(!vis[i]) g[get(pts[i].second.first)].push_back({pts[i].second.second,i});
}
for(int i = 0;i < xs.size();++i) {
sort(g[i].begin(),g[i].end());
}
return;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> N;
for(int i = 0;i < N;++i) {
long long x,y,r;
cin >> x >> y >> r;
pts.push_back({{r,i},{x + 1e9,y + 1e9}});
}
sort(pts.begin(),pts.end(),[&](auto a,auto b) {return make_pair(-a.first.first,a.first.second) < make_pair(-b.first.first,b.first.second);});
reconstruct(1e18);
for(int i = 0;i < N;++i) {
if(vis[i]) continue;
// cout << "TERMINATOR " << i << " " << (pts[i].first.second + 1) << endl;
if(pts[i].first.first * 2 <= gl) {
// reconstruct(pts[i].first.first);
}
int x = get(pts[i].second.first);
long long y = pts[i].second.second;
long long r = pts[i].first.first;
int index = pts[i].first.second;
for(int j = max(0,x - 2);j <= min(x + 2,(int)xs.size() - 1);++j) {
// auto itr = lower_bound(g[j].begin(),g[j].end(),make_pair(y - r,-1));
for(auto itr = g[j].begin();itr != g[j].end();++itr) {
if(check(i,itr -> second)) {
// cout << (itr -> second) << endl;
if(!vis[itr -> second]) vis[itr -> second] = index + 1;
}
}
}
}
for(int i = 0;i < N;++i) {
ans[pts[i].first.second] = vis[i];
}
for(int i = 0;i < N;++i) {
cout << ans[i] << " \n"[i == N - 1];
}
return 0;
}
Compilation message
circle_selection.cpp: In function 'void reconstruct(long long int)':
circle_selection.cpp:37:11: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
37 | for(auto [a,b] : pts) {
| ^
circle_selection.cpp:46:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
46 | for(int i = 0;i < xs.size();++i) {
| ~~^~~~~~~~~~~
circle_selection.cpp: In function 'int main()':
circle_selection.cpp:70:13: warning: unused variable 'y' [-Wunused-variable]
70 | long long y = pts[i].second.second;
| ^
circle_selection.cpp:71:13: warning: unused variable 'r' [-Wunused-variable]
71 | long long r = pts[i].first.first;
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
316 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
320 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
332 KB |
Output is correct |
7 |
Correct |
0 ms |
332 KB |
Output is correct |
8 |
Correct |
0 ms |
332 KB |
Output is correct |
9 |
Correct |
0 ms |
320 KB |
Output is correct |
10 |
Correct |
1 ms |
320 KB |
Output is correct |
11 |
Correct |
0 ms |
308 KB |
Output is correct |
12 |
Correct |
0 ms |
316 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
0 ms |
296 KB |
Output is correct |
15 |
Correct |
0 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
324 KB |
Output is correct |
19 |
Correct |
3 ms |
968 KB |
Output is correct |
20 |
Correct |
3 ms |
968 KB |
Output is correct |
21 |
Correct |
4 ms |
992 KB |
Output is correct |
22 |
Correct |
83 ms |
912 KB |
Output is correct |
23 |
Correct |
83 ms |
968 KB |
Output is correct |
24 |
Correct |
83 ms |
912 KB |
Output is correct |
25 |
Correct |
83 ms |
844 KB |
Output is correct |
26 |
Correct |
83 ms |
972 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
162 ms |
29456 KB |
Output is correct |
2 |
Correct |
178 ms |
29500 KB |
Output is correct |
3 |
Correct |
170 ms |
29308 KB |
Output is correct |
4 |
Correct |
158 ms |
29584 KB |
Output is correct |
5 |
Execution timed out |
3065 ms |
26220 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Execution timed out |
3062 ms |
8240 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3053 ms |
25140 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
316 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
320 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
332 KB |
Output is correct |
7 |
Correct |
0 ms |
332 KB |
Output is correct |
8 |
Correct |
0 ms |
332 KB |
Output is correct |
9 |
Correct |
0 ms |
320 KB |
Output is correct |
10 |
Correct |
1 ms |
320 KB |
Output is correct |
11 |
Correct |
0 ms |
308 KB |
Output is correct |
12 |
Correct |
0 ms |
316 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
0 ms |
296 KB |
Output is correct |
15 |
Correct |
0 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
324 KB |
Output is correct |
19 |
Correct |
3 ms |
968 KB |
Output is correct |
20 |
Correct |
3 ms |
968 KB |
Output is correct |
21 |
Correct |
4 ms |
992 KB |
Output is correct |
22 |
Correct |
83 ms |
912 KB |
Output is correct |
23 |
Correct |
83 ms |
968 KB |
Output is correct |
24 |
Correct |
83 ms |
912 KB |
Output is correct |
25 |
Correct |
83 ms |
844 KB |
Output is correct |
26 |
Correct |
83 ms |
972 KB |
Output is correct |
27 |
Correct |
7 ms |
1476 KB |
Output is correct |
28 |
Correct |
6 ms |
1476 KB |
Output is correct |
29 |
Correct |
6 ms |
1456 KB |
Output is correct |
30 |
Correct |
360 ms |
1436 KB |
Output is correct |
31 |
Correct |
345 ms |
1476 KB |
Output is correct |
32 |
Correct |
396 ms |
1476 KB |
Output is correct |
33 |
Correct |
63 ms |
12288 KB |
Output is correct |
34 |
Correct |
62 ms |
12304 KB |
Output is correct |
35 |
Correct |
127 ms |
12164 KB |
Output is correct |
36 |
Execution timed out |
3089 ms |
10436 KB |
Time limit exceeded |
37 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
316 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
320 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
332 KB |
Output is correct |
7 |
Correct |
0 ms |
332 KB |
Output is correct |
8 |
Correct |
0 ms |
332 KB |
Output is correct |
9 |
Correct |
0 ms |
320 KB |
Output is correct |
10 |
Correct |
1 ms |
320 KB |
Output is correct |
11 |
Correct |
0 ms |
308 KB |
Output is correct |
12 |
Correct |
0 ms |
316 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
0 ms |
296 KB |
Output is correct |
15 |
Correct |
0 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
324 KB |
Output is correct |
19 |
Correct |
3 ms |
968 KB |
Output is correct |
20 |
Correct |
3 ms |
968 KB |
Output is correct |
21 |
Correct |
4 ms |
992 KB |
Output is correct |
22 |
Correct |
83 ms |
912 KB |
Output is correct |
23 |
Correct |
83 ms |
968 KB |
Output is correct |
24 |
Correct |
83 ms |
912 KB |
Output is correct |
25 |
Correct |
83 ms |
844 KB |
Output is correct |
26 |
Correct |
83 ms |
972 KB |
Output is correct |
27 |
Correct |
162 ms |
29456 KB |
Output is correct |
28 |
Correct |
178 ms |
29500 KB |
Output is correct |
29 |
Correct |
170 ms |
29308 KB |
Output is correct |
30 |
Correct |
158 ms |
29584 KB |
Output is correct |
31 |
Execution timed out |
3065 ms |
26220 KB |
Time limit exceeded |
32 |
Halted |
0 ms |
0 KB |
- |