제출 #1315525

#제출 시각아이디문제언어결과실행 시간메모리
1315525vlomaczkRoad Construction (JOI21_road_construction)C++20
0 / 100
7940 ms71820 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> typedef long long ll; using namespace __gnu_pbds; using namespace std; template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; struct Point { ll x, y; }; ll M = 250'010; vector<ll> cnt(M,1); ll n; ll inf = 1e18; vector<Point> pkt; ll base = 1<<18; vector<vector<ll>> T(2*base); vector<ll> X; void build() { for(ll i=0; i<n; ++i) X.push_back(pkt[i].x); sort(X.begin(), X.end()); for(ll i=0; i<n; ++i) { ll idx = lower_bound(X.begin(), X.end(), pkt[i].x) - X.begin(); ll x = idx+base; while(x>0) { T[x].push_back(pkt[i].y); x/=2; } } for(int i=1; i<2*base; ++i) sort(T[i].begin(), T[i].end()); } int amount(vector<ll> &x, ll l, ll r) { return upper_bound(x.begin(), x.end(), r) - lower_bound(x.begin(), x.end(), l); } ll kwadrat(ll x, ll y, ll r) { ll a = lower_bound(X.begin(), X.end(), x-r) - X.begin(); ll b = upper_bound(X.begin(), X.end(), x+r) - X.begin() - 1; a += base-1; b += base+1; ll res = 0; while(a/2 != b/2) { if(a%2==0) res += amount(T[a+1], y-r, y+r); if(b%2==1) res += amount(T[b-1], y-r, y+r); a/=2; b/=2; } return res; } ll find_nxt(ll i) { ll lo = 0; ll hi = 4e9; if(cnt[i]==n) return inf; while(lo < hi) { ll mid = (lo+hi)/2; if(kwadrat(pkt[i].x, pkt[i].y, mid) > cnt[i]) hi = mid; else lo = mid+1; } cnt[i]++; return lo; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ll k; cin >> n >> k; pkt.resize(n); for(ll i=0; i<n; ++i) { ll x,y; cin >> x >> y; pkt[i] = {x+y,x-y}; } build(); priority_queue<pair<ll, ll>> pq; for(ll i=0; i<n; ++i) { pq.push({-find_nxt(i), i}); } 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...