#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 5;
long long sqr(long long x){ return x * x; }
struct circle{
long long x, y, r;
bool intersect(circle A){
return sqr(x - A.x) + sqr(y - A.y) <= sqr(r + A.r);
}
};
int n;
circle a[N];
namespace subtask1{
int ans[N];
void solve(){
while (true){
long long maxr = 0;
int idx = 0;
for (int i = 1; i <= n; ++ i) if (!ans[i] && a[i].r > maxr){
idx = i;
maxr = a[i].r;
}
if (!idx) break;
for (int i = 1; i <= n; ++ i) if (!ans[i] && a[idx].intersect(a[i])) ans[i] = idx;
}
for (int i = 1; i <= n; ++ i) cout << ans[i] << ' ';
}
}
vector <int> sr;
namespace subtask2{
int ans[N];
set <pair <int, int>> l, r;
void solve(){
for (int i = 1; i <= n; ++ i) {
l.insert({a[i].x - a[i].r, i});
r.insert({a[i].x + a[i].r, i});
}
for (int id : sr){
if (ans[id]) continue;
int le = a[id].x - a[id].r;
int ri = a[id].x + a[id].r;
auto it = l.lower_bound({le, 0});
while (it != l.end() && it -> first <= ri){
int del = it -> second;
ans[del] = id;
++ it;
l.erase({a[del].x - a[del].r, del});
r.erase({a[del].x + a[del].r, del});
}
it = r.lower_bound({le, 0});
while (it != r.end() && it -> first <= ri){
int del = it -> second;
ans[del] = id;
++ it;
l.erase({a[del].x - a[del].r, del});
r.erase({a[del].x + a[del].r, del});
}
}
for (int i = 1; i <= n; ++ i) cout << ans[i] << ' ';
}
}
namespace subtask4{
using pii = pair <int, int>;
map <pii, set <int>> grid;
int ans[N];
void solve(){
int radius = a[1].r;
for (int i = 1; i <= n; ++ i){
int x = a[i].x / radius;
int y = a[i].y / radius;
grid[{x, y}].insert(i);
}
for (int id : sr){
if (ans[id]) continue;
int x = a[id].x / radius;
int y = a[id].y / radius;
for (int i = x - 2; i <= x + 2; ++ i){
for (int j = y - 2; j <= y + 2; ++ j){
auto it1 = grid.find({i, j});
if (it1 == grid.end()) continue;
for (auto it = (it1 -> second).begin(); it != (it1 -> second).end();){
if (a[id].intersect(a[*it])){
ans[*it] = id;
it = (it1 -> second).erase(it);
}
else ++ it;
}
}
}
}
for (int i = 1; i <= n; ++ i) cout << ans[i] << ' ';
}
}
namespace Acepted{
void solve(){
}
}
void solve(){
cin >> n;
bool ck2 = true;
bool ck4 = true;
for (int i = 1; i <= n; ++ i) {
sr.push_back(i);
cin >> a[i].x >> a[i].y >> a[i].r;
if (a[i].y != 0) ck2 = false;
if (i > 1 && a[i].r != a[i - 1].r) ck4 = false;
}
sort(sr.begin(), sr.end(), [&](int u, int v){
if (a[u].r == a[v].r) return u < v;
return a[u].r > a[v].r;
});
if (n <= 5000) subtask1::solve();
else if (ck2) subtask2::solve();
else if (ck4) subtask4::solve();
else Acepted::solve();
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
solve();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4440 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
12 |
Correct |
1 ms |
4444 KB |
Output is correct |
13 |
Correct |
1 ms |
4444 KB |
Output is correct |
14 |
Correct |
1 ms |
4440 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
1 ms |
4444 KB |
Output is correct |
17 |
Correct |
1 ms |
4444 KB |
Output is correct |
18 |
Correct |
1 ms |
4440 KB |
Output is correct |
19 |
Correct |
3 ms |
4700 KB |
Output is correct |
20 |
Correct |
3 ms |
4700 KB |
Output is correct |
21 |
Correct |
3 ms |
4700 KB |
Output is correct |
22 |
Correct |
76 ms |
4680 KB |
Output is correct |
23 |
Correct |
89 ms |
4700 KB |
Output is correct |
24 |
Correct |
73 ms |
4756 KB |
Output is correct |
25 |
Correct |
70 ms |
4700 KB |
Output is correct |
26 |
Correct |
70 ms |
4756 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
538 ms |
48560 KB |
Output is correct |
2 |
Correct |
578 ms |
48520 KB |
Output is correct |
3 |
Correct |
509 ms |
48128 KB |
Output is correct |
4 |
Correct |
525 ms |
48568 KB |
Output is correct |
5 |
Correct |
445 ms |
46592 KB |
Output is correct |
6 |
Correct |
476 ms |
46612 KB |
Output is correct |
7 |
Correct |
449 ms |
46760 KB |
Output is correct |
8 |
Correct |
445 ms |
46792 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Incorrect |
32 ms |
9792 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1137 ms |
63428 KB |
Output is correct |
2 |
Correct |
734 ms |
63344 KB |
Output is correct |
3 |
Correct |
335 ms |
44400 KB |
Output is correct |
4 |
Correct |
771 ms |
63692 KB |
Output is correct |
5 |
Correct |
803 ms |
63948 KB |
Output is correct |
6 |
Correct |
247 ms |
37616 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4440 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
12 |
Correct |
1 ms |
4444 KB |
Output is correct |
13 |
Correct |
1 ms |
4444 KB |
Output is correct |
14 |
Correct |
1 ms |
4440 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
1 ms |
4444 KB |
Output is correct |
17 |
Correct |
1 ms |
4444 KB |
Output is correct |
18 |
Correct |
1 ms |
4440 KB |
Output is correct |
19 |
Correct |
3 ms |
4700 KB |
Output is correct |
20 |
Correct |
3 ms |
4700 KB |
Output is correct |
21 |
Correct |
3 ms |
4700 KB |
Output is correct |
22 |
Correct |
76 ms |
4680 KB |
Output is correct |
23 |
Correct |
89 ms |
4700 KB |
Output is correct |
24 |
Correct |
73 ms |
4756 KB |
Output is correct |
25 |
Correct |
70 ms |
4700 KB |
Output is correct |
26 |
Correct |
70 ms |
4756 KB |
Output is correct |
27 |
Incorrect |
5 ms |
4956 KB |
Output isn't correct |
28 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4440 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
12 |
Correct |
1 ms |
4444 KB |
Output is correct |
13 |
Correct |
1 ms |
4444 KB |
Output is correct |
14 |
Correct |
1 ms |
4440 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
1 ms |
4444 KB |
Output is correct |
17 |
Correct |
1 ms |
4444 KB |
Output is correct |
18 |
Correct |
1 ms |
4440 KB |
Output is correct |
19 |
Correct |
3 ms |
4700 KB |
Output is correct |
20 |
Correct |
3 ms |
4700 KB |
Output is correct |
21 |
Correct |
3 ms |
4700 KB |
Output is correct |
22 |
Correct |
76 ms |
4680 KB |
Output is correct |
23 |
Correct |
89 ms |
4700 KB |
Output is correct |
24 |
Correct |
73 ms |
4756 KB |
Output is correct |
25 |
Correct |
70 ms |
4700 KB |
Output is correct |
26 |
Correct |
70 ms |
4756 KB |
Output is correct |
27 |
Correct |
538 ms |
48560 KB |
Output is correct |
28 |
Correct |
578 ms |
48520 KB |
Output is correct |
29 |
Correct |
509 ms |
48128 KB |
Output is correct |
30 |
Correct |
525 ms |
48568 KB |
Output is correct |
31 |
Correct |
445 ms |
46592 KB |
Output is correct |
32 |
Correct |
476 ms |
46612 KB |
Output is correct |
33 |
Correct |
449 ms |
46760 KB |
Output is correct |
34 |
Correct |
445 ms |
46792 KB |
Output is correct |
35 |
Correct |
1 ms |
4444 KB |
Output is correct |
36 |
Incorrect |
32 ms |
9792 KB |
Output isn't correct |
37 |
Halted |
0 ms |
0 KB |
- |