Submission #434033

#TimeUsernameProblemLanguageResultExecution timeMemory
434033wiwihoLong Distance Coach (JOI17_coach)C++14
100 / 100
436 ms39024 KiB
#include <bits/stdc++.h> #include <bits/extc++.h> #define StarBurstStream ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); #define iter(a) a.begin(), a.end() #define riter(a) a.rbegin(), a.rend() #define lsort(a) sort(iter(a)) #define gsort(a) sort(riter(a)) #define pb(a) push_back(a) #define eb(a) emplace_back(a) #define pf(a) push_front(a) #define ef(a) emplace_front(a) #define pob pop_back() #define pof pop_front() #define mp(a, b) make_pair(a, b) #define F first #define S second #define mt make_tuple #define gt(t, i) get<i>(t) #define tomax(a, b) ((a) = max((a), (b))) #define tomin(a, b) ((a) = min((a), (b))) #define topos(a) ((a) = (((a) % MOD + MOD) % MOD)) #define uni(a) a.resize(unique(iter(a)) - a.begin()) #define printv(a, b) {bool pvaspace=false; \ for(auto pva : a){ \ if(pvaspace) b << " "; pvaspace=true;\ b << pva;\ }\ b << "\n";} using namespace std; using namespace __gnu_pbds; typedef long long ll; typedef unsigned long long ull; typedef long double ld; using pii = pair<int, int>; using pll = pair<ll, ll>; using pdd = pair<ld, ld>; using tiii = tuple<int, int, int>; const ll MOD = 1000000007; const ll MAX = 1LL << 60; template<typename A, typename B> ostream& operator<<(ostream& o, pair<A, B> p){ return o << '(' << p.F << ',' << p.S << ')'; } ll ifloor(ll a, ll b){ if(b < 0) a *= -1, b *= -1; if(a < 0) return (a - b + 1) / b; else return a / b; } ll iceil(ll a, ll b){ if(b < 0) a *= -1, b *= -1; if(a > 0) return (a + b - 1) / b; else return a / b; } struct Line{ ll a = 0, b = MAX; ll operator()(ll x){ return a * x + b; } }; vector<Line> st; void modify(Line ln, int L, int R, int id){ int M = (L + R) / 2; if(ln(M) < st[id](M)){ swap(ln, st[id]); } if(L == R) return; if(ln.a >= st[id].a) modify(ln, L, M, 2 * id + 1); else modify(ln, M + 1, R, 2 * id + 2); } void modify(int l, int r, Line ln, int L, int R, int id){ if(l == L && r == R){ modify(ln, L, R, id); return; } int M = (L + R) / 2; if(r <= M) modify(l, r, ln, L, M, 2 * id + 1); else if(l > M) modify(l, r, ln, M + 1, R, 2 * id + 2); else{ modify(l, M, ln, L, M, 2 * id + 1); modify(M + 1, r, ln, M + 1, R, 2 * id + 2); } } ll query(int pos, int L, int R, int id){ if(L == R) return st[id](pos); int M = (L + R) / 2; if(pos <= M) return min(st[id](pos), query(pos, L, M, 2 * id + 1)); else return min(st[id](pos), query(pos, M + 1, R, 2 * id + 2)); } int main(){ StarBurstStream ll X, T, W; int n, m; cin >> X >> n >> m >> W >> T; st.resize(4 * (m + 1)); vector<ll> s(n + 1); for(int i = 0; i < n; i++) cin >> s[i]; s[n] = X; lsort(s); vector<pll> tmp(m + 1); for(int i = 1; i <= m; i++){ cin >> tmp[i].F >> tmp[i].S; } lsort(tmp); vector<ll> D(m + 1), C(m + 1); for(int i = 1; i <= m; i++){ D[i] = tmp[i].F; C[i] = tmp[i].S; } vector<vector<ll>> sp(m + 2); for(ll i : s){ int id = upper_bound(iter(D), i % T) - D.begin(); id--; // cerr << "sp " << i << " " << id + 1 << "\n"; sp[id + 1].eb(i); } vector<ll> dp(m + 2); for(int i = 1; i <= m; i++) dp[m + 1] += C[i]; dp[m + 1] += iceil(X, T) * W; // cerr << "test " << m + 1 << " " << dp[m + 1] << "\n"; for(ll i : sp[m + 1]){ ll t = i / T; auto it = lower_bound(iter(s), i); int lst; if(it == s.begin()) lst = 1; else{ it--; if(i - *it >= T) lst = 1; else{ int id = upper_bound(iter(D), *it) - D.begin(); if(id >= m + 1) lst = 1; else lst = id; } } modify(lst, m + 1, Line({- t * W, (m + 1) * t * W + dp[m + 1]}), 1, m + 1, 0); } for(int pos = m; pos >= 1; pos--){ ll cnt = X / T; if(X % T > D[pos]) cnt++; dp[pos] = min(dp[pos + 1] + cnt * W - C[pos], query(pos, 1, m + 1, 0)); // cerr << "test " << pos << " " << cnt << " " << dp[pos] << " " << dp[pos + 1] + cnt * W - C[pos] << " " << query(pos, 1, m + 1, 0) << "\n"; for(ll i : sp[pos]){ ll t = i / T; auto it = lower_bound(iter(s), i); int lst; if(it == s.begin()) lst = 1; else{ it--; if(i - *it >= T) lst = 1; else{ int id = upper_bound(iter(D), *it) - D.begin(); if(id >= pos) lst = 1; else lst = id; } } modify(lst, pos, Line({- t * W, pos * t * W + dp[pos]}), 1, m + 1, 0); } } cout << dp[1] << "\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...