# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
581907 | 8e7 | Meetings (IOI18_meetings) | C++17 | 5539 ms | 6956 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "meetings.h"
//Challenge: Accepted
#include <bits/stdc++.h>
using namespace std;
#ifdef zisk
void debug(){cout << endl;}
template<class T, class ... U> void debug(T a, U ... b){cout << a << " ", debug(b...);}
template<class T> void pary(T l, T r) {
while (l != r) cout << *l << " ", l++;
cout << endl;
}
#else
#define debug(...) 0
#define pary(...) 0
#endif
#define ll long long
#define maxn 100005
#define pii pair<int, int>
#define ff first
#define ss second
#define io ios_base::sync_with_stdio(0);cin.tie(0);
const ll inf = 1LL<<60;
int lef[maxn], rig[maxn];
ll ls[maxn], rs[maxn];
std::vector<long long> minimum_costs(std::vector<int> H, std::vector<int> L,
std::vector<int> R) {
int q = L.size();
vector<ll> ret(q, 0);
for (int id = 0;id < q;id++) {
vector<int> h;
h.push_back(1<<30);
for (int i = L[id];i <= R[id];i++) h.push_back(H[i]);
h.push_back(1<<30);
int n = h.size() - 2;
for (int i = 0;i <= n+1;i++) {
ls[i] = rs[i] = 0;
}
stack<int> stk;
stk.push(0);
for (int i = 1;i <= n+1;i++) {
while (stk.size() && h[i] >= h[stk.top()]) stk.pop();
if (stk.size()) lef[i] = stk.top();
ls[i] = (ll)h[i] * (i - lef[i]) + ls[lef[i]];
stk.push(i);
}
while (stk.size()) stk.pop();
stk.push(n+1);
for (int i = n;i >= 0;i--) {
while (stk.size() && h[i] >= h[stk.top()]) stk.pop();
if (stk.size()) rig[i] = stk.top();
rs[i] = (ll)h[i] * (rig[i] - i) + rs[rig[i]];
stk.push(i);
}
ll ans = inf;
for (int i = 1;i <=n;i++) {
debug(ls[i], rs[i], h[i]);
ans = min(ans, ls[i] + rs[i] - h[i]);
}
debug();
ret[id] = ans;
}
return ret;
}
/*
4 2
2 4 3 5
0 2
1 3
*/
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |