제출 #253658

#제출 시각아이디문제언어결과실행 시간메모리
253658EntityIT원 고르기 (APIO18_circle_selection)C++14
15 / 100
1747 ms58812 KiB
#include <bits/stdc++.h> using namespace std; #define ALL(x) (x).begin(), (x).end() #define SZ(x) static_cast<int>((x).size()) template<class T, size_t D> struct vec : vector<vec<T, D - 1>> { template<class... Args> vec(size_t n = 0, Args... args) : vector<vec<T, D - 1>>(n, vec<T, D - 1>(args...)) {} }; template<class T> struct vec<T, 1> : vector<T> { template<class... Args> vec(Args... args) : vector<T>(args...) {} }; template<class T> inline bool Minimize(T& a, const T& b) { return a > b ? a = b, true : false; } template<class T> inline bool Maximize(T& a, const T& b) { return a < b ? a = b, true : false; } inline int Next(int i, int n) { return i == n - 1 ? 0 : i + 1; } inline int Prev(int i, int n) { return !i ? n - 1 : i - 1; } mt19937 rng(static_cast<uint32_t>(chrono::steady_clock::now().time_since_epoch().count())); struct Circle { int x, y, r; Circle(int t_x = 0, int t_y = 0, int t_r = 0) : x(t_x), y(t_y), r(t_r) {} bool CheckIntersection(const Circle& o) const { return static_cast<int64_t>(x - o.x) * (x - o.x) + static_cast<int64_t>(y - o.y) * (y - o.y) <= static_cast<int64_t>(r + o.r) * (r + o.r); } }; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n_circles; cin >> n_circles; vec<Circle, 1> circles(n_circles); int min_x, min_y; min_x = min_y = numeric_limits<int>::max(); for (auto& circle : circles) { cin >> circle.x >> circle.y >> circle.r; Minimize(min_x, circle.x); Minimize(min_y, circle.y); } for (auto& circle : circles) { circle.x -= min_x; circle.y -= min_y; } vec<int, 1> ord_circles(n_circles); iota(ALL(ord_circles), 0); sort(ALL(ord_circles), [&](int i, int j) { return circles[i].r != circles[j].r ? circles[i].r > circles[j].r : i < j; }); int scaler = 31; vec<pair<int, int>, 2> members_groups(1); for (int i = 0; i < n_circles; ++i) { members_groups[0].emplace_back(circles[i].y, i); } sort(ALL(members_groups[0])); vec<bool, 1> deleted(n_circles); vec<int, 1> answers(n_circles); for (auto& idx_circle : ord_circles) { if (!deleted[idx_circle]) { deleted[idx_circle] = true; answers[idx_circle] = idx_circle; while (scaler && circles[idx_circle].r <= (1 << (scaler - 1))) { --scaler; vec<pair<int, int>, 2> next_members_groups; for (auto& members : members_groups) { array<vec<pair<int, int>, 1>, 2> tmp_members; for (auto& member : members) { if (deleted[member.second]) { continue; } tmp_members[(circles[member.second].x >> scaler) & 1].emplace_back(member); } if (SZ(tmp_members[0])) { next_members_groups.emplace_back(tmp_members[0]); } if (SZ(tmp_members[1])) { next_members_groups.emplace_back(tmp_members[1]); } } members_groups.swap(next_members_groups); } for (auto it_members_groups = lower_bound(ALL(members_groups), (circles[idx_circle].x >> scaler) - 2, [&](vec<pair<int, int>, 1> i, int j) { return (circles[i[0].second].x >> scaler) < j; }); it_members_groups != members_groups.end() && (circles[(*it_members_groups)[0].second].x >> scaler) <= (circles[idx_circle].x >> scaler) + 2; ++it_members_groups) { for (auto it_members = lower_bound(ALL(*it_members_groups), (circles[idx_circle].y >> scaler) - 2, [&](pair<int, int> i, int j) { return (i.first >> scaler) < j; }); it_members != it_members_groups->end() && (it_members->first >> scaler) <= (circles[idx_circle].y >> scaler) + 2; ++it_members) { if (circles[idx_circle].CheckIntersection(circles[it_members->second])) { deleted[it_members->second] = true; answers[it_members->second] = idx_circle; } } } } } for (auto& answer : answers) { cout << answer + 1 << ' '; } cout << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...