이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 + 1;
cout << ans[i] << " ";
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |