Submission #981957

#TimeUsernameProblemLanguageResultExecution timeMemory
981957xiaowuc1Circle selection (APIO18_circle_selection)C++17
100 / 100
1971 ms52144 KiB
#include <algorithm> #include <array> #include <bitset> #include <cassert> #include <chrono> #include <cstring> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <stack> #include <unordered_map> #include <vector> using namespace std; // BEGIN NO SAD #define rep(i, a, b) for(int i = a; i < (b); ++i) #define trav(a, x) for(auto& a : x) #define all(x) x.begin(), x.end() #define sz(x) (int)(x).size() #define mp make_pair #define pb push_back #define eb emplace_back #define lb lower_bound #define ub upper_bound typedef vector<int> vi; #define f first #define s second #define derr if(0) cerr void __print(int x) {cerr << x;} void __print(long x) {cerr << x;} void __print(long long x) {cerr << x;} void __print(unsigned x) {cerr << x;} void __print(unsigned long x) {cerr << x;} void __print(unsigned long long x) {cerr << x;} void __print(float x) {cerr << x;} void __print(double x) {cerr << x;} void __print(long double x) {cerr << x;} void __print(char x) {cerr << '\'' << x << '\'';} void __print(const char *x) {cerr << '\"' << x << '\"';} void __print(const string &x) {cerr << '\"' << x << '\"';} void __print(bool x) {cerr << (x ? "true" : "false");} template<typename T, typename V> void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ", "; __print(x.second); cerr << '}';} template<typename T> void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? ", " : ""), __print(i); cerr << "}";} void _print() {cerr << "]\n";} template <typename T, typename... V> void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);} #define debug(x...) cerr << "\e[91m"<<__func__<<":"<<__LINE__<<" [" << #x << "] = ["; _print(x); cerr << "\e[39m" << flush; // END NO SAD template<class Fun> class y_combinator_result { Fun fun_; public: template<class T> explicit y_combinator_result(T &&fun): fun_(std::forward<T>(fun)) {} template<class ...Args> decltype(auto) operator()(Args &&...args) { return fun_(std::ref(*this), std::forward<Args>(args)...); } }; template<class Fun> decltype(auto) y_combinator(Fun &&fun) { return y_combinator_result<std::decay_t<Fun>>(std::forward<Fun>(fun)); } template<class T> bool updmin(T& a, T b) { if(b < a) { a = b; return true; } return false; } template<class T> bool updmax(T& a, T b) { if(b > a) { a = b; return true; } return false; } typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<vector<ll>> matrix; void solve() { int n; cin >> n; vector<array<ll, 4>> circles(n); vector<array<ll, 3>> meta(n); auto touch = [&](int i, int j) { ll x = meta[i][0] - meta[j][0]; ll y = meta[i][1] - meta[j][1]; ll r = meta[i][2] + meta[j][2]; return x*x+y*y <= r*r; }; for(int i = 0; i < n; i++) { ll x, y, r; cin >> x >> y >> r; x += 2e9; y += 2e9; assert(x >= r); assert(y >= r); circles[i] = {x, y, r, i}; meta[i] = {x, y, r}; } sort(all(circles), [&](auto a, auto b) -> bool { if(a[2] != b[2]) return a[2] > b[2]; return a[3] < b[3]; }); vector<int> ret(n, -1); vector<bool> gone(n); int CIRCLE_SIZE = 1 << 30; bool dirty = false; vector<array<ll, 2>> coords; vector<vector<int>> locs; for(auto circ: circles) { if(gone[circ[3]]) continue; while(CIRCLE_SIZE > circ[2]) { CIRCLE_SIZE /= 2; dirty = true; } if(dirty) { coords.clear(); locs.clear(); for(int i = 0; i < n; i++) { if(gone[i]) continue; auto [x, y, r] = meta[i]; ll xl = x; ll yl = y; xl /= CIRCLE_SIZE; yl /= CIRCLE_SIZE; coords.pb({xl, yl}); } sort(all(coords)); coords.erase(unique(all(coords)), coords.end()); locs.resize(sz(coords)); for(int i = 0; i < n; i++) { if(gone[i]) continue; auto [x, y, r] = meta[i]; ll xl = x; ll yl = y; xl /= CIRCLE_SIZE; yl /= CIRCLE_SIZE; int tidx = lb(all(coords), array<ll, 2>({xl, yl})) - coords.begin(); assert(tidx < sz(coords)); assert(coords[tidx][0] == xl); assert(coords[tidx][1] == yl); locs[tidx].pb(i); } dirty = false; } auto [x, y, r, idx] = circ; assert(!gone[idx]); ret[idx] = idx; gone[idx] = true; ll xl = x-r, xr = x+r; ll yl = y-r, yr = y+r; xl /= CIRCLE_SIZE, yl /= CIRCLE_SIZE; xr /= CIRCLE_SIZE, yr /= CIRCLE_SIZE; for(ll a = xl-2; a <= xr+2; a++) for(ll b = yl-2; b <= yr+2; b++) { int tidx = lb(all(coords), array<ll, 2>({a, b})) - coords.begin(); if(tidx == sz(coords) || coords[tidx] != array<ll, 2>({a, b})) continue; vector<int> nv; for(auto out: locs[tidx]) { if(gone[out]) continue; if(!touch(idx, out)) { nv.pb(out); } else { gone[out] = true; ret[out] = idx; } } if(sz(nv)) swap(locs[tidx], nv); } } for(int i = 0; i < n; i++) cout << ++ret[i] << " \n"[i == n-1]; } // what would chika do // are there edge cases (N=1?) // are array sizes proper (scaled by proper constant, for example 2* for koosaga tree) // integer overflow? // DS reset properly between test cases // are you doing geometry in floating points // are you not using modint when you should int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); solve(); }
#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...