제출 #842410

#제출 시각아이디문제언어결과실행 시간메모리
842410arnold518추월 (IOI23_overtaking)C++17
9 / 100
11 ms22880 KiB
#include "overtaking.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int MAXN = 1000; const ll INF = 1e18; int L, N; pll P[MAXN+10]; int M, S[MAXN+10]; ll X; int C[MAXN+10]; ll A[MAXN+10], B[MAXN+10], A2[MAXN+10][MAXN+10], ans[MAXN+10][MAXN+10]; struct CHT { vector<pair<pll, int>> V; CHT() {} ll cross(pll p, pll q) { ll x=q.second-p.second, y=p.first-q.first; if(y<0) x*=-1, y*=-1; if(x<0) return -1; return x/y; } ll f(pll p, ll y) { return (y-p.second+p.first-1)/p.first; } bool f2(pll p1, pll p2, ll y) { return (__int128)(y-p1.second)*p2.first<(y-p2.second); } void push(pll p, int q) { while(!V.empty() && (V.back().first.first==p.first || cross(V[V.size()-1].first, p)<0)) V.pop_back(); while(V.size()>1 && (V.back().first.first==p.first || cross(V[V.size()-2].first, V[V.size()-1].first)<=cross(V[V.size()-1].first, p))) V.pop_back(); V.push_back({p, q}); //printf("CHT1\n"); //for(auto it : V) printf("%lld %lld %d\n", it.first.first, it.first.second, it.second); } pll query(ll y) { //if(V.size()>1) printf("CHT2 %lld %lld\n", f(V[V.size()-2].first, y), f(V[V.size()-1].first, y)); while(V.size()>1 && f2(V[V.size()-2].first, V[V.size()-1].first, y)) V.pop_back(); //for(auto it : V) printf("%lld %lld %d\n", it.first.first, it.first.second, it.second); if(V.empty()) return {0, 0}; else { return {V.back().second, f(V.back().first, y)}; } } }; vector<ll> V1; vector<CHT> V2; void init(int _L, int _N, vector<ll> _T, vector<int> _W, int _X, int _M, vector<int> _S) { L=_L; N=_N; for(int i=1; i<=N; i++) P[i]=pll(_W[i-1], _T[i-1]); M=_M; X=_X; for(int i=0; i<M; i++) S[i]=_S[i]; M--; sort(P+1, P+N+1); reverse(P+1, P+N+1); while(N && P[N].first<=X) N--; //for(int i=1; i<=N; i++) printf("%lld %lld\n", P[i].first, P[i].second); for(int i=1; i<=N; i++) C[i]=i; for(int i=1; i<=N; i++) A[i]=P[i].second; for(int i=1; i<=N; i++) A2[i][0]=A[i]; for(int i=1; i<=M; i++) { for(int j=1; j<=N; j++) B[j]=A[j]+(ll)(S[i]-S[i-1])*P[j].first; sort(C+1, C+N+1, [&](const int &p, const int &q) { return pll(A[p], B[p])<pll(A[q], B[q]); }); ll t=0; for(int j=1; j<=N; j++) A[C[j]]=t=max(t, B[C[j]]); for(int j=1; j<=N; j++) A2[j][i]=A[j]; } for(int i=M; i>=0; i--) { sort(C+1, C+N+1, [&](const int &p, const int &q) { return A2[p][i]<A2[q][i]; }); CHT cht; for(int j=1; j<=N;) { auto p=cht.query(A2[C[j]][i]); p.second+=S[i]; //printf("%d %lld : %lld %lld\n", C[j], A2[C[j]][i], p.first, p.second); ll val; if(p.first==0) val=A2[C[j]][i]+X*(L-S[i]); else { if(p.second>L) val=A2[C[j]][i]+X*(L-S[i]); else { int it=lower_bound(S, S+M+1, p.second)-S; val=ans[p.first][it]; } } ll tt=A2[C[j]][i]; for(; j<=N && A2[C[j]][i]==tt; j++) { ans[C[j]][i]=val; //printf("!%d : %lld %lld\n", C[j], P[C[j]].first-X, A2[C[j]][i]); cht.push({P[C[j]].first-X, A2[C[j]][i]}, C[j]); } if(i==0) V1.push_back(tt), V2.push_back(cht); } //printf("=======\n"); } /* for(int i=0; i<=M; i++) { for(int j=1; j<=N; j++) printf("%lld ", ans[j][i]); printf("\n"); } for(int i=0; i<=M; i++) { for(int j=1; j<=N; j++) printf("%lld ", A2[j][i]); printf("\n"); }*/ } ll arrival_time(ll Y) { auto it=lower_bound(V1.begin(), V1.end(), Y); if(it==V1.begin()) return Y+X*L; it--; auto &cht = V2[it-V1.begin()]; int lo=0, hi=cht.V.size(); while(lo+1<hi) { int mid=lo+hi>>1; if(cht.f(cht.V[mid-1].first, Y)>=cht.f(cht.V[mid].first, Y)) lo=mid; else hi=mid; } pll p; if(cht.V.empty()) p={0, 0}; else p=pll(cht.V[lo].second, cht.f(cht.V[lo].first, Y)); //for(auto it : cht.V) printf("%d %lld\n", it.second, cht.f({P[it.second].first-X, A2[it.second][0]}, Y)); //for(int i=1; i<=N; i++) if(A2[i][0]<Y) printf("%d %lld %.10lf\n", i, cht.f({P[i].first-X, A2[i][0]}, Y), (double)(Y-A2[i][0])/(P[i].first-X)); //for(auto it : cht.V) printf("!%d %lld %lld\n", it.second, it.first.first, it.first.second); //pll p=cht.query(Y); //printf("%lld %lld\n", p.first, p.second); if(p.first==0) return Y+X*L; else { if(p.second>L) return Y+X*L; else { int it=lower_bound(S, S+M+1, p.second)-S; //printf("?%d %d\n", p.first ,it); return ans[p.first][it]; } } }

컴파일 시 표준 에러 (stderr) 메시지

overtaking.cpp: In function 'll arrival_time(ll)':
overtaking.cpp:140:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  140 |         int mid=lo+hi>>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...