Submission #112915

#TimeUsernameProblemLanguageResultExecution timeMemory
112915imaxblueMeetings (IOI18_meetings)C++17
0 / 100
19 ms1432 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define mp make_pair #define pb push_back #define x first #define y second #define pii pair<int, int> #define p3i pair<pii, int> #define pll pair<ll, ll> #define p3l pair<pll, ll> #define vi vector<int> #define vpii vector<pii> #define vp3i vector<p3i> #define vpll vector<pll> #define vp3l vector<p3l> #define lseg L, (L+R)/2, N*2+1 #define rseg (L+R)/2+1, R, N*2+2 #define ub upper_bound #define lb lower_bound #define pq priority_queue #define MN 1000000007 #define fox(k, x) for (int k=0; k<x; ++k) #define fox1(k, x) for (int k=1; k<=x; ++k) #define foxr(k, x) for (int k=x-1; k>=0; --k) #define fox1r(k, x) for (int k=x; k>0; --k) #define ms multiset #define flood(x) memset(x, 0x3f3f3f3f, sizeof x) #define drain(x) memset(x, 0, sizeof x) #define rng() ((rand() << 14)+rand()) #define scan(X) do{while((X=getchar())<'0'); for(X-='0'; '0'<=(_=getchar()); X=(X<<3)+(X<<1)+_-'0');}while(0) char _; #define pi 3.14159265358979323846 int n, q; ll lft[5005], rit[5005], curr; vector<ll> ans; vector<int> h; vector<pii> hi; void solve(int L, int R){ curr = 0; hi.clear(); hi.pb(mp((1<<30), L-1)); for (int l = L; l <= R; ++l){ // << h[l] << ' ' << hi.back().x << endl; while(hi.back().x < h[l]){ curr -= 1LL*(hi.back().y-hi[hi.size()-2].y)*(hi.back().x); hi.pop_back(); } curr += 1LL*(l - hi.back().y)*(h[l]); hi.pb(mp(h[l], l)); lft[l] = curr; //cout << lft[l] << ' '; } //cout << endl; curr = 0; hi.clear(); hi.pb(mp((1<<30), R+1)); for (int l = R; l >= L; --l){ while(hi.back().x < h[l]){ curr -= (hi[hi.size()-2].y-hi.back().y)*(hi.back().x); hi.pop_back(); } curr += (hi.back().y-l)*(h[l]); hi.pb(mp(h[l], l)); rit[l] = curr; //cout << rit[l] << ' '; } //cout << endl; ll res = (1LL<<60); for (int l = L; l<= R; ++l){ res = min(res, lft[l] + rit[l] - h[l]); } ans.pb(res); } vector<ll> minimum_costs(vector<int> H, vector<int> L, vector<int> R){ n = H.size(); q = L.size(); h = H; if (n <= 5000 && q <= 5000){ fox(l, q){ solve(L[l], R[l]); } return ans; } } /* int main(){ int n, q, h, x, y; vector<int> H, L, R; cin >> n >> q; fox(l, n){ cin >> h; H.pb(h); } fox(l, q){ cin >> x >> y; L.pb(x); R.pb(y); } vector<ll> res = minimum_costs(H, L, R); fox(l, res.size()) cout << res[l] << ' '; cout << endl; return 0; }*/ /* 4 2 2 4 3 5 0 2 1 3 */

Compilation message (stderr)

meetings.cpp: In function 'std::vector<long long int> minimum_costs(std::vector<int>, std::vector<int>, std::vector<int>)':
meetings.cpp:86:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
#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...