이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "meetings.h"
#include<bits/stdc++.h>
using namespace std;
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define P push
typedef long long ll;
vector<ll> minimum_costs(vector<int> H, vector<int> L,vector<int> R) {
int n,q;
n=H.size();q=L.size();
vector<ll> C;
for(int h=0;h<q;h++){
ll ans=INT64_MAX;
ll vall[n],valr[n];
vector<int> v;
ll cur=H[L[h]];vall[L[h]]=cur;
v.PB(L[h]);
for(int i=L[h]+1;i<=R[h];i++){
while(!v.empty()){
int last=v.back();
if(H[last]>=H[i])break;
v.pop_back();
if(v.empty())cur+=(H[i]-H[last])*(last-L[h]+1);
else cur+=(H[i]-H[last])*(last-v.back());
}
v.PB(i);cur+=H[i];
vall[i]=cur;
}
v.clear();
cur=H[R[h]];valr[R[h]]=cur;
v.PB(R[h]);
for(int i=R[h]-1;i>=L[h];i--){
while(!v.empty()){
int last=v.back();
if(H[last]>=H[i])break;
v.pop_back();
if(v.empty())cur+=(H[i]-H[last])*(R[h]-last+1);
else cur+=(H[i]-H[last])*(v.back()-last);
}
v.PB(i);cur+=H[i];
valr[i]=cur;
}
for(int i=L[h];i<=R[h];i++){
ans=min(ans,vall[i]+valr[i]-(ll)H[i]);
}
C.PB(ans);
}
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... |