#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int maxN = 3e5 + 5;
struct Circle{
ll x, y, r, id;
} C[maxN];
int n;
bool compC (Circle& a, Circle& b){
if(a.r == b.r) return a.id < b.id;
return a.r > b.r;
}
bool isect(Circle& a, Circle& b){
ll dx = a.x - b.x;
ll dy = a.y - b.y;
ll r = a.r + b.r;
return dx * dx + dy * dy <= r * r;
}
int ans[maxN];
map<pair<ll, ll>, vector<int>> block;
vector<int> tmp;
int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int n;
cin >> n;
for(int i = 1; i <= n; i++){
cin >> C[i].x >> C[i].y >> C[i].r;
C[i].id = i;
}
sort(C + 1, C + n + 1, compC);
for (int i = 1; i <= n; i++){
C[i].x += 1e9;
C[i].y += 1e9;
block[{C[i].x / C[i].r, C[i].y / C[i].r}].push_back(i);
}
for (int i = 1; i <= n; i++){
Circle& curr = C[i];
if (ans[curr.id]) continue;
for (ll x = curr.x / curr.r - 2; x <= curr.x / curr.r + 2; x++){
for (ll y = curr.y / curr.r - 2; y <= curr.y / curr.r + 2; y++){
if (block.find({x,y}) == block.end()) continue;
tmp.clear();
for (ll idx: block[{x,y}]){
if (ans[C[idx].id] == 0 && isect(C[idx], curr)) ans[C[idx].id] = curr.id;
else if (ans[C[idx].id] == 0) tmp.push_back(idx);
}
block[{x, y}] = tmp;
}
}
}
for (int i = 1; i <= n; i++)
cout << ans[i] << ' ';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
112 ms |
15160 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
969 ms |
45808 KB |
Output is correct |
2 |
Correct |
743 ms |
45652 KB |
Output is correct |
3 |
Correct |
291 ms |
22608 KB |
Output is correct |
4 |
Correct |
787 ms |
45648 KB |
Output is correct |
5 |
Correct |
753 ms |
45652 KB |
Output is correct |
6 |
Correct |
169 ms |
16240 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |