#include "bits/stdc++.h"
#define ll long long
using namespace std;
const ll mod = 1000000007;
signed main () {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
// freopen("cowland.in","r",stdin);
// freopen("cowland.out","w",stdout);
int n;
cin >> n;
vector<pair<int, pair<int, int>>> v;
int rr[n];
for(int i = 0; i < n; i++) {
int x, y, r;
cin >> x >> y >> r;
rr[i] = r;
v.push_back({x - r, {0, i}});
v.push_back({x + r, {1, i}});
}
sort(v.begin(), v.end());
priority_queue<pair<int, int>> pq;
int ans[n];
for(int i = 0; i < n; i++)
ans[i] = -1;
bool b[n] = {};
for(int i = n * 2 - 1; i >= 0; i--) {
if(v[i].second.first == 0) {
if(!pq.empty())
ans[v[i].second.second] = pq.top().second + 1;
pq.push({rr[v[i].second.second], v[i].second.second});
}
else {
b[v[i].second.second] = 1;
while(!pq.empty() && (b[pq.top().second] || ans[pq.top().second]))
b[pq.top().second] = 0, pq.pop();
}
}
for(int i = 0; i < n * 2; i++) {
if(v[i].second.first == 0) {
if(!pq.empty())
ans[v[i].second.second] = pq.top().second + 1;
pq.push({rr[v[i].second.second], v[i].second.second});
}
else {
b[v[i].second.second] = 1;
while(!pq.empty() && (b[pq.top().second] || ans[pq.top().second]))
b[pq.top().second] = 0, pq.pop();
}
}
for(int i = 0; i < n; i++) {
if(ans[i] == -1)
ans[i] = i;
cout << ans[i] << " ";
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
210 ms |
15936 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 |
182 ms |
13928 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 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |