# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
710636 | Cyanmond | Meetings (IOI18_meetings) | C++17 | 1 ms | 212 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"
#include <bits/stdc++.h>
using i64 = long long;
constexpr i64 inf = 1ll << 50;
std::vector<i64> solve(const std::vector<i64> &H) {
const int N = (int)H.size();
std::vector<i64> valList(N);
std::stack<std::pair<int, i64>> stk;
i64 sum = 0;
for (int i = 0; i < N; ++i) {
// update
int u = 1;
while ((not stk.empty()) and (stk.top().second <= H[i])) {
sum -= stk.top().second * stk.top().first;
u += stk.top().first;
stk.pop();
}
stk.push({u, H[i]});
sum += u * H[i];
valList[i] = sum;
}
return valList;
}
std::vector<long long> minimum_costs(std::vector<int> H, std::vector<int> L,
std::vector<int> R) {
int N = (int)H.size(), Q = (int)L.size();
std::vector<i64> answer(Q);
for (int i = 0; i < Q; ++i) {
std::vector<i64> h(R[i] - L[i] + 1);
for (int j = L[i]; j <= R[i]; ++j) h[j - L[i]] = H[j];
const auto x = solve(h);
std::reverse(h.begin(), h.end());
const auto y = solve(h);
i64 res = inf;
for (int j = 0; j < (R[i] - L[i] + 1); ++j) {
res = std::min(res, x[j] + y[j]);
}
answer[i] = res;
}
return answer;
}
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... |