#include<bits/stdc++.h>
using namespace std;
const int nax = 3e5 + 3;
long long sqrd(int x) {
return x * 1LL * x;
}
struct circle {
int x, y, r, j;
bool operator< (const circle& b) const {
if(r!=b.r) return r > b.r;
return j < b.j;
}
bool intersect(const circle& b) const {
return sqrd(x-b.x) + sqrd(y-b.y) <= sqrd(r+b.r);
}
} bag[nax];
bool cmp(circle a, circle b) {
return make_pair(a.x, a.r) < make_pair(b.x, b.r);
}
void PlayGround() {
int n;
cin>>n;
set<pair<int,int>>b, c;
set<pair<int,int>,greater<pair<int,int>>>a;
for(int i=0; i<n; ++i) {
int x, y, r;
cin>>x>>y>>r;
bag[i] = {x, y, r, i+1};
a.insert({2*r, n-i});
b.insert({x-r, i});
c.insert({x+r, i});
}
int ans[n+1];
while(!a.empty()) {
auto x = *a.begin();
a.erase(x);
circle cur = bag[n-x.second];
vector<int>cache;
while(1) {
auto it = b.lower_bound(make_pair(cur.x-cur.r, 0));
if(it==b.end() || it->first>cur.x+cur.r) break;
cache.push_back(it->second);
circle rem = bag[it->second];
b.erase(make_pair(rem.x-rem.r, rem.j-1));
c.erase(make_pair(rem.x+rem.r, rem.j-1));
}
while(1) {
auto it = c.lower_bound(make_pair(cur.x-cur.r, 0));
if(it==c.end() || it->first>cur.x+cur.r) break;
cache.push_back(it->second);
circle rem = bag[it->second];
b.erase(make_pair(rem.x-rem.r, rem.j-1));
c.erase(make_pair(rem.x+rem.r, rem.j-1));
}
for(int x : cache) {
ans[x+1] = cur.j;
a.erase(make_pair(2 * bag[x].r, x));
}
}
// int at[n+1];
// vector<circle>order;
// for(auto z : s) {
// order.push_back(z);
// }
// sort(order.begin(), order.end(), cmp);
// for(int i=0; i<n; ++i) {
// at[order[i].j] = i;
// }
// bool done[n+1] = {0};
// int ans[n+1];
// while(!s.empty()) {
// auto cur = *s.begin();
// s.erase(cur);
// int p = at[cur.j];
// while(p>=0 && !done[p] && cur.intersect(order[p])) {
// done[p] = true;
// ans[order[p].j] = cur.j;
// s.erase(order[p]);
// --p;
// }
// p = at[cur.j] + 1;
// while(p<n && !done[p] && cur.intersect(order[p])) {
// done[p] = true;
// ans[order[p].j] = cur.j;
// s.erase(order[p]);
// ++p;
// }
// }
for(int i=1; i<=n; ++i) {
cout<<ans[i]<<' ';
}
// cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
PlayGround();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1283 ms |
50824 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
819 ms |
49984 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |