이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "meetings.h"
#include <bits/stdc++.h>
using namespace std;
vector<int> h;
vector<long long> cost;
void addcosts(int from, int to, int update) {
long long adder = 0;
vector<pair<long long, int>> proc;
proc.push_back({INT_MAX, from-update});
for (int j=from; (from<=j && j<=to) || (to <= j && j <= from); j+=update) {
while (proc.back().first <= h[j]) {
long long t = proc.size();
long long co = abs(proc[t-1].second - proc[t-2].second) * proc[t-1].first;
adder -= co;
proc.pop_back();
}
proc.push_back({h[j], j});
long long t = proc.size();
long long co = abs(proc[t-1].second - proc[t-2].second) * proc[t-1].first;
adder += co;
cost[j] += adder;
}
}
std::vector<long long> minimum_costs(std::vector<int> H, std::vector<int> L,
std::vector<int> R) {
int Q = L.size();
std::vector<long long> C(Q);
int n = H.size();
h = H;
cost.resize(n, 0);
for (int i=0; i<Q; i++) {
int l = L[i], r = R[i];
for (int j=l; j<=r; j++) {
cost[j] = 0;
}
addcosts(l, r, 1);
addcosts(r, l, -1);
for (int i=l; i<=r; i++) {
cost[i] -= H[i];
}
C[i] = LLONG_MAX;
for (int j=l; j<=r; j++) {
C[i] = min(C[i], cost[j]);
}
}
return C;
}
# | 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... |