이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "meetings.h"
using namespace std;
vector<long long> minimum_costs(vector<int> H, vector<int> L, vector<int> R) {
int N = H.size();
int Q = L.size();
vector<long long> ans(Q);
if (Q <= 5000 && N <= 5000) {
for (int i = 0; i < Q; i++) {
vector<long long> cost_l(R[i] - L[i] + 2), cost_r(R[i] - L[i] + 2);
stack<pair<int, int>> st;
st.emplace(2e9, R[i] - L[i] + 1);
for (int j = R[i] - L[i]; j >= 0; j--) {
while (st.top().first <= H[j + L[i]]) st.pop();
cost_r[j] = cost_r[st.top().second] + (long long)H[j + L[i]] * (st.top().second - j);
st.emplace(H[j + L[i]], j);
}
while (!st.empty()) st.pop();
st.emplace(2e9, 0);
for (int j = 0; j <= R[i] - L[i]; j++) {
while (st.top().first <= H[j + L[i]]) st.pop();
cost_l[j + 1] = cost_l[st.top().second] + (long long)H[j + L[i]] * (j + 1 - st.top().second);
st.emplace(H[j + L[i]], j + 1);
}
ans[i] = 1e18;
for (int j = 0; j <= R[i] - L[i]; j++) {
ans[i] = min(ans[i], cost_l[j + 1] + cost_r[j] - H[j + L[i]]);
}
}
}
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... |