Submission #1032036

#TimeUsernameProblemLanguageResultExecution timeMemory
1032036GrindMachineOvertaking (IOI23_overtaking)C++17
100 / 100
2037 ms154836 KiB
#pragma GCC optimize("O3,unroll-loops") #pragma GCC target("avx2") #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; template<typename T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; typedef long long int ll; typedef long double ld; typedef pair<int,int> pii; typedef pair<ll,ll> pll; #define fastio ios_base::sync_with_stdio(false); cin.tie(NULL) #define pb push_back #define endl '\n' #define sz(a) (int)a.size() #define setbits(x) __builtin_popcountll(x) #define ff first #define ss second #define conts continue #define ceil2(x,y) ((x+y-1)/(y)) #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() #define yes cout << "Yes" << endl #define no cout << "No" << endl #define rep(i,n) for(int i = 0; i < n; ++i) #define rep1(i,n) for(int i = 1; i <= n; ++i) #define rev(i,s,e) for(int i = s; i >= e; --i) #define trav(i,a) for(auto &i : a) template<typename T> void amin(T &a, T b) { a = min(a,b); } template<typename T> void amax(T &a, T b) { a = max(a,b); } #ifdef LOCAL #include "debug.h" #else #define debug(x) 42 #endif /* already knew some key ideas */ const int MOD = 1e9 + 7; const int N = 1e3 + 5; const int inf1 = int(1e9) + 5; const ll inf2 = ll(1e18) + 5; #include "overtaking.h" template<typename T> struct lazysegtree { /*=======================================================*/ struct data { ll a; }; struct lazy { ll a; }; data d_neutral = {-1}; lazy l_neutral = {-1}; void merge(data &curr, data &left, data &right) { curr.a = max(left.a,right.a); } void create(int x, int lx, int rx, T v) { } void modify(int x, int lx, int rx, T v) { lz[x].a = v; } void propagate(int x, int lx, int rx) { ll v = lz[x].a; if(v == -1) return; tr[x].a = v; if(rx-lx > 1){ lz[x<<1].a = v; lz[x<<1|1].a = v; } lz[x] = l_neutral; } /*=======================================================*/ int siz = 1; vector<data> tr; vector<lazy> lz; lazysegtree() { } lazysegtree(int n) { while (siz < n) siz *= 2; tr.assign(2 * siz, d_neutral); lz.assign(2 * siz, l_neutral); } void build(vector<T> &a, int n, int x, int lx, int rx) { if (rx - lx == 1) { if (lx < n) { create(x, lx, rx, a[lx]); } return; } int mid = (lx + rx) >> 1; build(a, n, x<<1, lx, mid); build(a, n, x<<1|1, mid, rx); merge(tr[x], tr[x<<1], tr[x<<1|1]); } void build(vector<T> &a, int n) { build(a, n, 1, 0, siz); } void rupd(int l, int r, T v, int x, int lx, int rx) { propagate(x, lx, rx); if (lx >= r or rx <= l) return; if (lx >= l and rx <= r) { modify(x, lx, rx, v); propagate(x, lx, rx); return; } int mid = (lx + rx) >> 1; rupd(l, r, v, x<<1, lx, mid); rupd(l, r, v, x<<1|1, mid, rx); merge(tr[x], tr[x<<1], tr[x<<1|1]); } void rupd(int l, int r, T v) { rupd(l, r + 1, v, 1, 0, siz); } data query(int l, int r, int x, int lx, int rx) { propagate(x, lx, rx); if (lx >= r or rx <= l) return d_neutral; if (lx >= l and rx <= r) return tr[x]; int mid = (lx + rx) >> 1; data curr; data left = query(l, r, x<<1, lx, mid); data right = query(l, r, x<<1|1, mid, rx); merge(curr, left, right); return curr; } data query(int l, int r) { return query(l, r + 1, 1, 0, siz); } }; vector<ll> T; vector<int> W,S; ll X,m; vector<pll> segs; lazysegtree<ll> st; void init(int L, int n, std::vector<long long> T_, std::vector<int> W_, int X_, int M, std::vector<int> S_) { T = T_, W = W_, S = S_; X = X_, m = M; ll e[n][m], t[n][m]; rep(i,n){ e[i][0] = t[i][0] = T[i]; } rep1(j,m-1){ rep(i,n){ e[i][j] = t[i][j-1]+(ll)W[i]*(S[j]-S[j-1]); t[i][j] = e[i][j]; } vector<pll> ord; rep(i,n){ ord.pb({t[i][j-1],i}); } sort(all(ord)); ll ptr = 0, mx = 0; rep(i,n){ while(ptr < n and ord[ptr].ff < ord[i].ff){ amax(mx,e[ord[ptr].ss][j]); ptr++; } amax(t[ord[i].ss][j],mx); } } vector<ll> b; rep(i,n){ rep(j,m){ b.pb(t[i][j]-X*S[j]); } } sort(all(b)); b.resize(unique(all(b))-b.begin()); segs.pb({-inf2,b[0]-1}); rep(i,sz(b)){ segs.pb({b[i],b[i]}); if(i+1 < sz(b)){ segs.pb({b[i]+1,b[i+1]-1}); } } segs.pb({b.back()+1,inf2}); ll siz = sz(segs); st = lazysegtree<ll>(siz); ll f[n][m]; rep(i,n) f[i][m-1] = t[i][m-1]; rev(j,m-2,0){ vector<pll> ord; rep(i,n){ ord.pb({t[i][j+1],i}); } sort(all(ord)); for(auto [tv,i] : ord){ ll l = t[i][j]-X*S[j]; ll r = t[i][j+1]-X*S[j+1]; l = lower_bound(all(segs),pll{l,l})-segs.begin(); r = lower_bound(all(segs),pll{r,r})-segs.begin(); l++, r--; st.rupd(l,r,f[i][j+1]); } rep(i,n){ ll val = t[i][j]-X*S[j]; ll ind = lower_bound(all(segs),pll{val,val})-segs.begin(); f[i][j] = max(t[i][j]+X*(S[m-1]-S[j]),st.query(ind,ind).a); } } } long long arrival_time(long long t) { ll ind = lower_bound(all(segs),pll{t+1,-1})-segs.begin()-1; ll ans = max(t+X*S[m-1],st.query(ind,ind).a); return ans; }
#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...