# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
407588 | juggernaut | 원 고르기 (APIO18_circle_selection) | C++17 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using i64 = long long;
inline i64 sq(int x) { return i64(x) * x; }
int main(){
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int n;
std::cin >> n;
std::vector<int> x(n), y(n), r(n);
for (int i = 0; i < n; i++) {
std::cin >> x[i] >> y[i] >> r[i];
}
std::vector<int> ans(n, -1);
std::vector<int> ind(n);
iota(ind.begin(), ind.end(), 0);
sort(ind.begin(), ind.end(), [&](int i, int j) {
if (r[i] == r[j]) return i < j;
return r[i] > r[j];
});
std::set<std::pair<int, int>> sr;
for (int i = 0; i < n; i++) {
sr.emplace(x[i] + r[i], i);
sr.emplace(x[i] - r[i], i);
}
for (auto i : ind) {
if(~ans[i])continue;
while (sr.size()) {
auto it = sr.lower_bound({x[i] - r[i], -1});
if (it == sr.end()) break;
int j = it->second;
if(it->first>x[i]+r[i])break;
sr.erase(it);
if(~ans[it->second])continue;
ans[id->second]=i;
}
}
for (auto x : ans) assert(~x), std::cout << x + 1 << ' ';
std::cout << '\n';
}