Submission #1066804

#TimeUsernameProblemLanguageResultExecution timeMemory
1066804LittleOrangeOvertaking (IOI23_overtaking)C++17
0 / 100
1304 ms2097152 KiB
#include "overtaking.h" #include<bits/stdc++.h> using namespace std; using ll = long long; const ll big = 1e18; ll n,m,l,x; vector<vector<ll>> t,e; vector<ll> w,s; vector<vector<pair<ll,ll>>> vs; vector<vector<pair<ll,ll>>> lvl; set<pair<ll,ll>> all; struct node{ int l,r,m; ll v; node *lp, *rp; node(ll a, ll b):l(a),r(b),m((l+r)>>1),v(0),lp(nullptr),rp(nullptr){} node* L(){ if(lp==nullptr) lp = new node(l,m); return lp; } node* R(){ if(rp==nullptr) rp = new node(m+1,r); return rp; } void pull(){ if(lp) v = max(v,lp->v); if(rp) v = max(v,rp->v); } void upd(ll i, ll x){ if (l==r) v = max(v,x); else{ if (i<=m) L()->upd(i,x); else R()->upd(i,x); pull(); } } ll qry(ll ql, ll qr){ if(ql<=l&&r<=qr) return v; else{ ll ret = -big; if (ql<=m&&lp) ret = max(ret,lp->qry(ql,qr)); if (qr>m&&rp) ret = max(ret,rp->qry(ql,qr)); return ret; } } }; node* tree; void init(int L, int N, std::vector<long long> T, std::vector<int> w, int X, int M, std::vector<int> s) { n = N; m = M; l = L; x = X; tree = new node(-100,big); t.resize(n+1,vector<ll>(m)); for(ll i = 0;i<n;i++) t[i][0] = T[i]; e = t; vs.emplace_back(); for(ll j = 1;j<m;j++){ vector<pair<ll,ll>> v; for(ll i = 0;i<n;i++){ t[i][j] = e[i][j] = t[i][j-1]+w[i]*(s[j]-s[j-1]); v.push_back({t[i][j-1],e[i][j]}); } sort(v.begin(),v.end()); for(ll i = 1;i<n;i++){ v[i].second = max(v[i].second,v[i-1].second); } for(ll i = 0;i<n;i++){ auto it = lower_bound(v.begin(),v.end(),make_pair(t[i][j-1],0ll)); if (it==v.begin()) continue; --it; t[i][j] = max(t[i][j],(*it).second); } vs.push_back(v); } for(auto [a,b] : vs.back()){ tree->upd(a+x*(s[m-1]-s[m-2]),b); //all.insert({a+x*(s[m-1]-s[m-2]),b}); } for(ll j = m-2;j>0;j--){ for(auto [a,b] : vs[j]){ ll nw = b+x*(s[m-1]-s[j]); ll g = tree->qry(0,nw-1); nw = max(nw,g); //b = nw; tree->upd(a+x*(s[m-1]-s[j-1]),b); //all.insert({a+x*(s[m-1]-s[j-1]),b}); } } /*for(ll j = 1;j<m;j++){ for(auto [a,b] : lvl[j]){ //cout << j << " " << a << " " << b << "\n"; //cout << a-x*(S[j-1]-S[0]) << " " << b << "\n"; all.push_back({a-x*(S[j-1]-S[0]),b}); } } sort(all.begin(),all.end()); for(ll i = 1;i<all.size();i++){ all[i].second = max(all[i].second,all[i-1].second); }*/ //cout << "e:\n"; //for(ll i = 0;i<n;i++) for(ll j = 0;j<m;j++) cout << e[i][j] << " \n"[j+1==m]; //cout << "t:\n"; //for(ll i = 0;i<n;i++) for(ll j = 0;j<m;j++) cout << t[i][j] << " \n"[j+1==m]; //for(auto [a,b] : all){ // cout << a << " " << b << "\n"; //} } long long arrival_time(long long Y) { /*for(ll j = 1;j<m;j++){ auto it = lower_bound(vs[j].begin(),vs[j].end(),make_pair(Y,0ll)); ll nxt = Y+x*(s[j]-s[j-1]); if (it!=vs[j].begin()){ --it; nxt = max(nxt,(*it).second); } Y = nxt; }*/ ll ans = Y+x*l; ll g = tree->qry(0,ans-1); ans = max(ans,g); 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...