이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "meetings.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int Q,N;
unordered_map<int,int> m;
int c = 0;
vector<long long> minimum_costs(vector<int> H, vector<int> L, vector<int> R) {
Q = L.size(); N = H.size();
auto sortH = H;
sort(sortH.begin(),sortH.end());
for (auto h: sortH) {
if (m.count(h) == 0) m[h] = c++;
}
vector<long long> C(Q,-1);
for (int q = 0; q < Q; q++) {
vector<ll> costLeft(R[q]-L[q]+1), costRight(R[q]-L[q]+1);
vector<pair<ll,ll>> fromRight, fromLeft; //height,index
for (int x = L[q]; x <= R[q]; x++) {
costLeft[x-L[q]] = (x == L[q] ? 0 : costLeft[x-L[q]-1]);
int cur = x-1;
while (fromLeft.size() > 0 && fromLeft.back().first < H[x]) {
costLeft[x-L[q]] -= fromLeft.back().first*(cur-fromLeft.back().second);
// cout << costLeft[1] << "\n";
cur = fromLeft.back().second;
fromLeft.pop_back();
}
costLeft[x-L[q]] += (long long)H[x]*(x-cur);
// cout << costLeft[x-L[q]] << "\n";
fromLeft.push_back(make_pair(H[x],cur));
}
// cout << "\n";
for (int x = R[q]; x >= L[q]; x--) {
costRight[x-L[q]] = (x == R[q] ? 0 : costRight[x-L[q]+1]);
int cur = x+1;
while (fromRight.size() > 0 && fromRight.back().first < H[x]) {
costRight[x-L[q]] -= fromRight.back().first*(fromRight.back().second-cur);
// cout << costRight[1] << "\n";
cur = fromRight.back().second;
fromRight.pop_back();
}
costRight[x-L[q]] -= (long long)H[x]*(x-cur);
//cout << costRight[x-L[q]] << "\n";
fromRight.push_back(make_pair(H[x],cur));
}
for (int x = L[q]; x <= R[q]; x++) {
ll val = costRight[x-L[q]] + costLeft[x-L[q]] - H[x];
// cout << costLeft[x-L[q]] << " " << costRight[x-L[q]] << " " << H[x] << "\n";
//cout << costRight[x-1] << " " << costLeft[x] << " " << H[x] << " " << val << "\n";
C[q] = (C[q] == -1 ? val : min(C[q],val));
}
//C[q] = ; //TODO
}
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... |