이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "meetings.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll inf = 1e18;
vector<ll> minimum_costs(vector<int> H, vector<int> L, vector<int> R) {
int N = H.size(), Q = L.size();
vector<ll> ans(Q, inf);
for (int i = 0; i < Q; i++) {
vector<int> stk;
vector<ll> A(N);
for (int j = L[i]; j <= R[i]; j++) {
while (!stk.empty() && H[stk.back()] <= H[j]) {
stk.pop_back();
}
if (stk.empty()) {
A[j] = 1LL * H[j] * (j - (L[i] - 1));
} else {
A[j] = 1LL * H[j] * (j - stk.back()) + A[stk.back()];
}
stk.push_back(j);
}
stk.clear();
vector<ll> B(N);
for (int j = R[i]; j >= L[i]; j--) {
while (!stk.empty() && H[stk.back()] <= H[j]) {
stk.pop_back();
}
if (stk.empty()) {
B[j] = 1LL * H[j] * ((R[i] + 1) - j);
} else {
B[j] = 1LL * H[j] * (stk.back() - j) + B[stk.back()];
}
stk.push_back(j);
}
for (int j = L[i]; j <= R[i]; j++) {
ans[i] = min(ans[i], A[j] + B[j] - H[j]);
}
}
return ans;
}
# | 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... |