Submission #765884

#TimeUsernameProblemLanguageResultExecution timeMemory
765884khshgMeetings (IOI18_meetings)C++14
17 / 100
55 ms11192 KiB
#include<bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using str = string; using pi = pair<int, int>; using pl = pair<ll, ll>; using pd = pair<ld, ld>; #define mp make_pair #define ff first #define ss second #define ar array template<class T> using V = vector<T>; using vi = V<int>; using vb = V<bool>; using vl = V<ll>; using vd = V<ld>; using vs = V<str>; using vpi = V<pi>; using vpl = V<pl>; using vpd = V<pd>; #define sz(x) (int)((x).size()) #define bg(x) begin(x) #define all(x) bg(x), end(x) #define rall(x) (x).rbegin(), (x).rend() #define sor(x) sort(all(x)) #define rsz resize #define ins insert #define pb push_back #define eb emplace_back #define ft front() #define bk back() #define lb lower_bound #define ub upper_bound #define FOR(i, a, b) for(int i = (a); i < (b); ++i) #define F0R(i, a) FOR(i, 0, a) #define ROF(i, a, b) for(int i = (b) - 1; i >= (a); --i) #define R0F(i, a) ROF(i, 0, a) #define rep(a) F0R(_, a) #define trav(a, x) for(auto& a : x) template<class T> bool ckmin(T& a, const T& b) { return (b < a ? a = b, 1 : 0); } template<class T> bool ckmax(T& a, const T& b) { return (b > a ? a = b, 1 : 0); } const ll INF = 0x3f3f3f3f3f3f3f3f; template<typename T> struct Sparse_Table { int lgflr(int x) { return 31 - __builtin_clz(x); } T f(T x, T y) { // implement !!! return max(x, y); } int N, K; vector<vector<T>> st; void init(vector<T> a) { N = (int) a.size(); K = lgflr(N); st = vector<vector<T>>(K + 1, vector<T>(N)); swap(st[0], a); for(int i = 1; i <= K; ++i) { for(int j = 0; j + (1 << i) <= N; ++j) { st[i][j] = f(st[i - 1][j], st[i - 1][j + (1 << (i - 1))]); } } } T query(int L, int R) { int i = lgflr(R - L + 1); return f(st[i][L], st[i][R - (1 << i) + 1]); } }; vl minimum_costs(vi H, vi L, vi R) { int N = sz(H); vpi is; F0R(i, N) { if(H[i] == 2) continue; int j = i; while(j + 1 < N && H[j + 1] == 1) { ++j; } is.eb(i, j); i = j; } vi K(sz(is)); F0R(i, sz(is)) K[i] = is[i].ss - is[i].ff + 1; Sparse_Table<int> mx; mx.init(K); int Q = sz(L); vl ans(Q); F0R(q, Q) { int l; { int tl = 0, tr = sz(is) - 1; l = -1; while(tl <= tr) { int tm = (tl + tr) / 2; if(is[tm].ff < L[q]) { l = tm; tl = tm + 1; } else { tr = tm - 1; } } } if(l != -1 && is[l].ss >= L[q]) ckmax(ans[q], (ll)is[l].ss - L[q] + 1); ++l; int r; { int tl = 0, tr = sz(is) - 1; r = tr + 1; while(tl <= tr) { int tm = (tl + tr) / 2; if(is[tm].ss > R[q]) { r = tm; tr = tm - 1; } else { tl = tm + 1; } } } if(r < sz(is) && is[r].ff <= R[q]) ckmax(ans[q], (ll)R[q] - is[r].ff + 1); --r; if(l <= r) ckmax(ans[q], (ll)mx.query(l, r)); ckmin(ans[q], (ll)(R[q] - L[q] + 1)); ans[q] = 2 * (R[q] - L[q] + 1 - ans[q]) + ans[q]; } 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...