이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <complex>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <functional>
#include <bitset>
#include <queue>
#include <map>
#include <stack>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <vector>
//#include "meetings.h"
using namespace std;
#define endl '\n'
#define db double
#define ll long long
#define pb push_back
#define fs first
#define sd second
#define Mod long(1e9 + 7)
#define all(x) x.begin(), x.end()
#define unvisited long(-1)
#define Eps double(1e-9)
#define _for(i, n) for(int i = 0; i < (n); i++)
#define dbg(x) cout << #x ": " << x << endl;
const ll Max = 1e6 + 7, Inf = 1e17 + 7LL;
void clear_vec(vector <ll> &v){
for(auto& u : v) u = 0;
}
vector<long long> minimum_costs(vector<int> H, vector<int> L, vector<int> R)
{
int n = H.size(), q = L.size();
vector <ll> v(n);
auto F = [&](int l, int r) -> ll
{
priority_queue <ll> h;
clear_vec(v);
ll sum = 0;
while(!h.empty()){
h.pop();
}
for(int i = l; i <= r; i++){
h.push(-H[i]); sum = sum + ((ll) H[i]);
while (!h.empty())
{
int x = abs(h.top());
if(H[i] > x){
sum += abs(H[i] - x);
h.pop();
} else break;
}
v[i] += sum;
}
sum = 0;
while(!h.empty()){
h.pop();
}
for(int i = r; i >= l; i--){
h.push(-H[i]); sum = sum + ((ll) H[i]);
while (!h.empty())
{
int x = abs(h.top());
if(H[i] > x){
sum += abs(H[i] - x);
h.pop();
} else break;
}
v[i] += sum;
}
ll sol = Inf;
for(int i = l; i <= r; i++){
sol = min(sol, v[i] - H[i]);
}
return sol;
};
vector <ll> ans(q);
for(int i = 0; i < q; i++){
//ans[i] = St.query(L[i], R[i]);
ans[i] = F(L[i], R[i]);
}
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... |