Submission #1157874

#TimeUsernameProblemLanguageResultExecution timeMemory
1157874gazizmadi11Road Construction (JOI21_road_construction)C++20
6 / 100
2326 ms30792 KiB
//gm --- akezhon #include <bits/stdc++.h> // #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3") // #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #define pb push_back #define pf push_front #define F first #define S second #define all(v) v.begin(),v.end() #define pii pair<int,int> #define tm (tl+tr)/2 #define TL v+v, tl, tm #define TR v+v+1, tm+1, tr #define DA l <= tl && tr <= r #define NE r < tl || tr < l #define double long double #define ll long long using namespace std; const int N=250007; const int mod=998244353; const ll inf=1e10; ll n, k; pair<ll,ll> a[N]; ll check(int l, int r, ll d){ if(l==r)return 0; int m = (l+r)/2, ans=0; set<int>st1, st2; // possible y's on each side for(int i=l; i <= r; i++){ if(abs(a[m].F-a[i].F) > d)continue; if(i <= m)st1.insert(a[i].S); else st2.insert(a[i].S); } vector<int>y1,y2; for(int i : st1)y1.pb(i); for(int i : st2)y2.pb(i); vector<vector<int>>v1(y1.size()), v2(y2.size()); for(int i=l; i <= r; i++){ if(abs(a[m].F-a[i].F) > d)continue; if(i <= m){ int pos = lower_bound(all(y1), a[i].S)-y1.begin(); v1[pos].pb(a[i].F); } else{ int pos = lower_bound(all(y2), a[i].S)-y2.begin(); v2[pos].pb(a[i].F); } } // cout << v1[0][0] << ' ' << v1[0][1] << " " << v2[0][0] << ' ' << v2[0][1] << '\n'; for(int i=0; i < y1.size(); i++){ for(int j=0; j < y2.size(); j++){ if(abs(y1[i]-y2[j]) > d)continue; int pos=0; for(int h=0; h < v1[i].size(); h++){ while(pos < v2[j].size() && (ll)(v2[j][pos]-v1[i][h] + abs(y1[i]-y2[j])) <= d)pos++; ans += pos; if(ans > k)return inf; } } } return ans+check(l, m, d)+check(m+1, r, d); } vector<ll>vec; void show(int l, int r, int d){ if(l==r)return; int m = (l+r)/2, ans=0; set<int>st1, st2; // possible y's on each side for(int i=l; i <= r; i++){ if(abs(a[m].F-a[i].F) > d)continue; if(i <= m)st1.insert(a[i].S); else st2.insert(a[i].S); } vector<int>y1,y2; for(int i : st1)y1.pb(i); for(int i : st2)y2.pb(i); vector<vector<int>>v1(y1.size()), v2(y2.size()); for(int i=l; i <= r; i++){ if(abs(a[m].F-a[i].F) > d)continue; if(i <= m){ int pos = lower_bound(all(y1), a[i].S)-y1.begin(); v1[pos].pb(a[i].F); } else{ int pos = lower_bound(all(y2), a[i].S)-y2.begin(); v2[pos].pb(a[i].F); } } for(int i=0; i < y1.size(); i++){ for(int j=0; j < y2.size(); j++){ if(abs(y1[i]-y2[j]) > d)continue; for(int h=0; h < v1[i].size(); h++){ for(int f=0; f < v2[j].size(); f++){ if((ll)(v2[j][f]-v1[i][h] + abs(y1[i]-y2[j])) > d)break; vec.pb((ll)(v2[j][f]-v1[i][h] + abs(y1[i]-y2[j]))); } } } } show(l, m, d); show(m+1, r, d); } void AlemAmenov(){ cin >> n >> k; for(int i=1; i <= n; i++){ cin >> a[i].F >> a[i].S; } sort(a+1, a+1+n); ll l=0, r=4e9, ans; while(l <= r){ int m=(l+r)/2; if(k <= check(1, n, m))r=m-1, ans=m; else l=m+1; } if(check(1, n, ans) != k)ans--; show(1, n, ans); while(vec.size() != k)vec.pb(ans+1); sort(all(vec)); for(int i : vec){ cout << i << '\n'; } } signed main(){ ios_base::sync_with_stdio(0); cin.tie(0); int RealName=1; // cin >> RealName; // freopen("newbarn.in", "r", stdin); // freopen("newbarn.out", "w", stdout); while(RealName--) AlemAmenov(); 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...