Submission #921808

#TimeUsernameProblemLanguageResultExecution timeMemory
921808browntoadRoad Construction (JOI21_road_construction)C++14
100 / 100
9675 ms129040 KiB
#include <bits/stdc++.h> #pragma GCC optimize ("Ofast", "unroll-loops") using namespace std; #define ll long long #define int ll #define FOR(i,a,b) for (int i = (a); i<(b); i++) #define REP(i,n) FOR(i,0,n) #define REP1(i,n) FOR(i,1,n+1) #define RREP(i,n) for (int i=(n)-1; i>=0; i--) #define RREP1(i,n) for (int i=(n); i>=1; i--) #define f first #define s second #define pb push_back #define ALL(x) x.begin(),x.end() #define SZ(x) (int)(x.size()) #define SQ(x) (x)*(x) #define pii pair<int, int> #define pip pair<int, pii> #define ppi pair<pii, int> #define pdd pair<double ,double> #define pcc pair<char, char> #define endl '\n' //#define TOAD #ifdef TOAD #define bug(x) cerr<<__LINE__<<": "<<#x<<" is "<<x<<endl #define IOS() #else #define bug(...) #define IOS() ios::sync_with_stdio(0), cin.tie(0), cout.tie(0) #endif const ll inf = 1ll<<60; const int iinf=2147483647; const ll mod = 998244353; const ll maxn = 250005; const ll maxm=15; const double PI=acos(-1); ll pw(ll x, ll p, ll m=mod){ if (p < 0) return 0; ll ret=1; while (p>0){ if (p&1){ ret*=x; ret%=m; } x*=x; x%=m; p>>=1; } return ret; } ll inv(ll a, ll m=mod){ return pw(a,m-2,m); } int n, k, cur = 0, M; bool gg = false; vector<vector<pii>> ord(4*maxn); vector<pii> vc; int ans[maxn]; void initO(int l, int r, int x){ if (l == r){ ord[x].pb(vc[l]); return; } int mid = l+r>>1; initO(l, mid, x+x); initO(mid+1, r, x+x+1); int lptr = 0, rptr = 0; while(lptr < SZ(ord[x+x]) || rptr < SZ(ord[x+x+1])){ if (lptr == SZ(ord[x+x])) ord[x].pb(ord[x+x+1][rptr++]); else if (rptr == SZ(ord[x+x+1])) ord[x].pb(ord[x+x][lptr++]); else if (ord[x+x][lptr].s <= ord[x+x+1][rptr].s) ord[x].pb(ord[x+x][lptr++]); else ord[x].pb(ord[x+x+1][rptr++]); } } void init(){ cin>>n>>k; REP(i, n){ int x, y; cin>>x>>y; vc.pb({x, y}); } sort(ALL(vc)); initO(0, n-1, 1); } void run(int l, int r, int x){ if (l == r) return; if (gg) return; int mid = l+r>>1; run(l, mid, x+x); if (gg) return; run(mid+1, r, x+x+1); if (gg) return; multiset<int> R; int rp = 0; pii v; REP(i, SZ(ord[x+x])){ v = ord[x+x][i]; while(rp < SZ(ord[x+x+1]) && ord[x+x+1][rp].s <= v.s){ R.insert(-ord[x+x+1][rp].s+ord[x+x+1][rp].f-vc[mid].f); rp++; } if (SZ(R)){ auto it = R.begin(); while(it != R.end() && (*it)+v.s+(vc[mid].f-v.f) <= M){ ans[cur++] = (*it)+v.s+(vc[mid].f-v.f); it++; if (cur >= k){ gg = 1; return; } } } } R.clear(); rp = SZ(ord[x+x+1])-1; RREP(i, SZ(ord[x+x])){ v = ord[x+x][i]; while(rp >= 0 && ord[x+x+1][rp].s > v.s){ R.insert(ord[x+x+1][rp].s+ord[x+x+1][rp].f-vc[mid].f); rp--; } if (SZ(R)){ auto it = R.begin(); while(it != R.end() && (*it)-v.s+(vc[mid].f-v.f) <= M){ ans[cur++] = (*it)-v.s+(vc[mid].f-v.f); it++; if (cur >= k){ gg = 1; return; } } } } } signed main(){ IOS(); init(); int L = 0, R = 4000000000ll; while(L <= R){ M = L+R+1>>1; gg = 0; cur = 0; run(0, n-1, 1); if (L == R) break; if (gg) R = M-1; else L = M; } vector<int> fans; REP(i, cur){ fans.pb(ans[i]); } while(SZ(fans) < k) fans.pb(L+1); sort(ALL(fans)); REP(i, SZ(fans)){ cout<<fans[i]<<endl; } // cout<<L<<endl; }

Compilation message (stderr)

road_construction.cpp: In function 'void initO(long long int, long long int, long long int)':
road_construction.cpp:69:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   69 |     int mid = l+r>>1;
      |               ~^~
road_construction.cpp: In function 'void run(long long int, long long int, long long int)':
road_construction.cpp:94:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   94 |     int mid = l+r>>1;
      |               ~^~
road_construction.cpp: In function 'int main()':
road_construction.cpp:147:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  147 |         M = L+R+1>>1;
      |             ~~~^~
#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...