이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "meetings.h"
#include <bits/stdc++.h>
using namespace std;
template<typename T>
using min_heap = priority_queue<T, vector<T>, greater<T>>;
template<typename T>
using max_heap = priority_queue<T, vector<T>, less<T>>;
using int64 = long long;
using ld = long double;
constexpr int kInf = 1e9 + 10;
constexpr int64 kInf64 = 1e18 + 10;
constexpr int kMod = 1e9 + 7;
std::vector<long long> minimum_costs(std::vector<int> H, std::vector<int> L, std::vector<int> R) {
const int n = H.size(), q = L.size();
vector<int64> ans(q, kInf64);
vector<int64> cost(n);
auto initialise_cost = [&]() {
for (int i = 0; i < n; i++) {
cost[i] = -H[i];
}
};
for (int query = 0; query < q; query++) {
initialise_cost();
for (const auto &[s, t] : {make_pair(L[query], R[query]), make_pair(R[query], L[query])}) {
vector<pair<int64, int>> stk = {{kInf64, 0}};
int64 sum = 0;
for (int i = s; i != t; (s < t ? i++ : i--)) {
int cnt = 1;
while (stk.back().first <= H[i]) {
const auto &[h, c] = stk.back();
cnt += c;
sum -= h * 1LL * c;
stk.pop_back();
}
stk.emplace_back(H[i], cnt);
sum += H[i] * 1LL * cnt;
cost[i] += sum;
}
}
ans[query] = *min_element(cost.begin() + L[query], cost.begin() + R[query] + 1);
}
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... |