제출 #1315645

#제출 시각아이디문제언어결과실행 시간메모리
1315645vlomaczkRoad Construction (JOI21_road_construction)C++20
65 / 100
10095 ms182632 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; friend bool operator<(Point a, Point b) { return a.y < b.y; } }; struct Node { ll sum; Node *l, *r; Node(ll s=0, Node* l=nullptr, Node* r=nullptr) : sum(s), l(l), r(r) {} }; Node* build(int a, int b) { if(a==b) return new Node(0); Node* m = new Node(0); int mid = (a+b)/2; m->l = build(a,mid); m->r = build(mid+1,b); return m; } Node* update(Node *root, int a, int b, int p, ll val) { if(b < p || a > p) return root; if(a==b) { return new Node(root->sum + val); } ll m = (a+b)/2; Node* newL = update(root->l, a, m, p, val); Node* newR = update(root->r, m+1, b, p, val); return new Node(newL->sum + newR->sum, newL, newR); } ll query(Node *root, int a, int b, int l, int r) { if(!r || b < l || r < a) return 0; if(l <= a && b <= r) return root->sum; int m = (a+b)/2; return query(root->l, a, m, l, r) + query(root->r, m+1, b, l, r); } ll M = 250'010; vector<ll> cnt(M,1); ll n; ll inf = 1e18; vector<Point> pkt; vector<ll> X, Y; vector<Node*> root(M); int base = 1<<18; int numer = 1; void init() { 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) Y.push_back(pkt[i].y); for(ll i=0; i<n; ++i) { ll idx = lower_bound(X.begin(), X.end(), pkt[i].x) - X.begin(); root[numer] = update(root[numer-1], 0, base-1, idx, 1); ++numer; } } 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 i, ll r) { auto[x,y] = pkt[i]; 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; ll left = i; ll right = upper_bound(Y.begin(), Y.end(), y+r) - Y.begin() - 1; return query(root[right+1], 0, base-1, a,b) - query(root[left],0,base-1,a,b); } 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(i, 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}; } sort(pkt.begin(), pkt.end()); root[0] = build(0,base-1); init(); priority_queue<pair<ll, ll>> pq; for(ll i=0; i<n; ++i) { pq.push({-find_nxt(i), i}); } for(ll ile=0; ile<k; ++ile){ cout << -pq.top().first << "\n"; ll i =pq.top().second; pq.pop(); 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...