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<bits/stdc++.h>
#define ll long long
#define pb push_back
#define vi vector<int>
#define fi first
#define se second
#define local
#ifndef local
#include "meetings.h"
#endif
using namespace std;
int Q,n;
vector<ll> small(vi H,vi L,vi R) {
vector<ll> T(Q);
for (int i = 0; i < Q; i++) {
int l = L[i], r = R[i];
stack<ll> st;
ll sum = 0;
vector<ll> ans(n),bans(n);
for (int x = l ; x <= r; x++) {
int e = 1;
if (st.size() && st.top() < H[x]) {
sum -= st.top();
st.pop();
sum += H[x];
e++;
}
while (e--) st.push(H[x]), sum += H[x];
ans[x] = sum;
}
while(!st.empty()) st.pop();
sum = 0;
for (int x = r; x >= l; x--) {
int e = 1;
if (st.size() && st.top() < H[x]) {
sum -= st.top();
st.pop();
sum += H[x];
e++;
}
while(e--) st.push(H[x]), sum += H[x];
sum -= H[x];
ans[i] += sum;
}
ll mn = LLONG_MAX;
for (int i = l; i <= r; i++) mn = min(mn,ans[i]);
T[i] = mn;
}
return T;
}
vector<ll> minimum_costs(vi H, vi L,vi R) {
n = H.size(); Q = L.size();
if (n <= 5000 && Q <= 5000) return small(H,L,R);
std::vector<long long> C(Q);
for (int j = 0; j < Q; ++j) {
C[j] = H[L[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... |