#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 = 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 = 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; i++) {
if(ans[i] == -1)
ans[i] = i;
cout << ans[i] << " ";
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
189 ms |
13916 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
186 ms |
13900 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |