Submission #846504

#TimeUsernameProblemLanguageResultExecution timeMemory
846504abcvuitunggioOvertaking (IOI23_overtaking)C++17
100 / 100
2657 ms919632 KiB
#include "overtaking.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair <ll, ll> pii; const ll INF=2e18; vector <pii> st; vector <int> le,ri; vector <pair <pii, int>> v; ll e[1001][1001],r[1001][1001],n,t[1001],w[1001],l,x,id; void gen(){ st.emplace_back(INF,INF); le.emplace_back(-1); ri.emplace_back(-1); id++; } void update(int node, ll l, ll r, ll u, ll v, pii p){ if (l>v||r<u||l>r||u>v) return; if (l>=u&&r<=v){ st[node]=min(st[node],p); return; } ll mid=(l+r)>>1; if (le[node]==-1){ le[node]=id; gen(); } update(le[node],l,mid,u,v,p); if (ri[node]==-1){ ri[node]=id; gen(); } update(ri[node],mid+1,r,u,v,p); } pii get(int node, ll l, ll r, ll i){ pii p={INF,i}; while (node!=-1){ p=min(p,st[node]); ll mid=(l+r)>>1; if (mid>=i){ r=mid; node=le[node]; } else{ l=mid+1; node=ri[node]; } } return p; } void init(int L, int N, vector <ll> T, vector <int> W, int X, int m, vector <int> s){ l=L; x=X; st.reserve(240LL*N*N); le.reserve(240LL*N*N); ri.reserve(240LL*N*N); for (int i=0;i<N;i++){ if (W[i]>x){ w[n]=W[i]; e[n][0]=t[n]=T[i]; n++; } } for (int i=1;i<m;i++){ for (int j=0;j<n;j++) v.push_back({{e[j][i-1],w[j]},j}); sort(v.begin(),v.end()); ll mx=0; for (int it=0;it<v.size();it++){ int j=v[it].second; mx=max(mx,e[j][i-1]+w[j]*(s[i]-s[i-1])); e[j][i]=mx; r[j][i-1]=min((it==v.size()-1?INF:e[v[it+1].second][i-1]),mx-x*(s[i]-s[i-1])); } v.clear(); } gen(); for (int i=m-1;i;i--){ for (int j=0;j<n;j++) v.push_back({{e[j][i],w[j]},j}); sort(v.begin(),v.end()); for (auto p:v){ int j=p.second; update(0,0,INF,e[j][i-1]+1+x*(l-s[i-1]),r[j][i-1]+x*(l-s[i-1]),{i,get(0,0,INF,e[j][i]+x*(l-s[i])).second}); } v.clear(); } } ll arrival_time(ll y){ return get(0,0,INF,y+x*l).second; }

Compilation message (stderr)

overtaking.cpp: In function 'void init(int, int, std::vector<long long int>, std::vector<int>, int, int, std::vector<int>)':
overtaking.cpp:70:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<std::pair<long long int, long long int>, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   70 |         for (int it=0;it<v.size();it++){
      |                       ~~^~~~~~~~~
overtaking.cpp:74:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<std::pair<long long int, long long int>, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   74 |             r[j][i-1]=min((it==v.size()-1?INF:e[v[it+1].second][i-1]),mx-x*(s[i]-s[i-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...