제출 #1078240

#제출 시각아이디문제언어결과실행 시간메모리
1078240c2zi6추월 (IOI23_overtaking)C++17
65 / 100
3557 ms34964 KiB
#define _USE_MATH_DEFINES #include <bits/stdc++.h> #define ff first #define ss second #define pb push_back #define all(a) (a).begin(), (a).end() #define replr(i, a, b) for (int i = int(a); i <= int(b); ++i) #define reprl(i, a, b) for (int i = int(a); i >= int(b); --i) #define rep(i, n) for (int i = 0; i < int(n); ++i) #define mkp(a, b) make_pair(a, b) using namespace std; typedef long long ll; typedef long double ld; typedef pair<int, int> PII; typedef vector<int> VI; typedef vector<PII> VPI; typedef vector<VI> VVI; typedef vector<VVI> VVVI; typedef vector<VPI> VVPI; typedef pair<ll, ll> PLL; typedef vector<ll> VL; typedef vector<PLL> VPL; typedef vector<VL> VVL; typedef vector<VVL> VVVL; typedef vector<VPL> VVPL; template<class T> T setmax(T& a, T b) {if (a < b) return a = b; return a;} template<class T> T setmin(T& a, T b) {if (a < b) return a; return a = b;} #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; template<class T> using indset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; #include "overtaking.h" struct SEGTREE { int n; VL tree; SEGTREE(){} SEGTREE(int sz) { n = 1; while (n < sz) n *= 2; tree = VL(2*n); } void upd(int N, int L, int R, int i, ll s) { if (i < L || i > R) return; if (L == R) { tree[N] = s; return; } int M = (L + R) / 2; upd(2*N+1, L, M, i, s); upd(2*N+2, M+1, R, i, s); tree[N] = max(tree[2*N+1], tree[2*N+2]); } ll get(int N, int L, int R, int l, int r) { if (R < l || L > r) return 0; if (l <= L && R <= r) return tree[N]; int M = (L + R) / 2; return max(get(2*N+1, L, M, l, r), get(2*N+2, M+1, R, l, r)); } void upd(int i, ll s) { upd(0, 0, n-1, i, s); } ll get(int l, int r) { return get(0, 0, n-1, l, r); } }; int n; VI W, S; VL T; int m; ll expected(int i, int j) { /* * i-rd avtobusin inchqan jamanak e petq * (j-1)-rd stanciaic j-rd stancia hasnelu hamar */ return 1ll * W[i] * (S[j] - S[j-1]); } typedef vector<tuple<ll, ll, int>> VLLI; VLLI a; VL step(VL t, int j) { int n = t.size(); /* * t[i]-n i-rd avtobusi (j-1)-rd stancia * hasnelu jamanakn e, petq everadardznel ret, * urdex ret[i]-n i-rd avtobusi j-rd stancia * hasnelu jamanakn e */ VL e(n); rep(i, n) e[i] = t[i] + expected(i, j); a = VLLI(n); rep(i, n) a[i] = {t[i], e[i], i}; sort(all(a)); ll maxexp = 0; VL ret(n); for (auto[t, e, i] : a) { setmax(maxexp, e); ret[i] = maxexp; } return ret; } struct BESTCHOICE { int n; VL times, values; SEGTREE seg; BESTCHOICE(){} BESTCHOICE(VLLI a) { n = a.size(); times = values = VL(); for (auto[t, e, i] : a) { times.pb(t); values.pb(e); } seg = SEGTREE(n); rep(i, n) seg.upd(i, values[i]); } ll operator()(ll x) { int ind = lower_bound(all(times), x) - times.begin() - 1; return seg.get(0, ind); } void print() { for (ll x : times) cout << x << " "; cout << endl; for (ll x : values) cout << x << " "; cout << endl; } }; vector<BESTCHOICE> best; void init(int L, int N_ARG, VL T_ARG, VI W_ARG, int X, int M, VI S_ARG) { n = N_ARG; W = W_ARG; W.pb(X); m = M; S = S_ARG; T = T_ARG; VL cur = T; replr(i, 1, m-1) { cur = step(cur, i); best.pb(BESTCHOICE(a)); } } ll arrival_time(ll Y) { replr(i, 1, m-1) { auto& p = best[i-1]; /*cout << "Kancinq hetevyal bani mijov" << endl;*/ /*p.print();*/ /*cout << "Expected@ " << Y + expected(n, i) << endl;*/ Y = max(Y + expected(n, i), p(Y)); /*cout << "Y dardzav " << Y << endl;*/ /*cout << endl;*/ } return Y; }
#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...