# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1073745 | shezitt | Meetings (IOI18_meetings) | C++14 | 0 ms | 0 KiB |
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>
#include "meetings.h"
using ll = long long;
#define fore(a, b, c) for(int a=b; a<c; ++a)
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using namespace std;
int T[6050], n;
void update(int idx, int x){
T[idx += n] = x;
for(idx /= 2; idx; idx /= 2){
T[idx] = max(T[2*idx], T[2*idx+1]);
}
}
int query(int low, int high){
int ra = 0, rb = 0;
for(low += n, high += n + 1; low < high; low /= 2, high /= 2){
if(low & 1) ra = max(ra, T[low++]);
if(high & 1) rb = max(rb, T[--high]);
}
return max(ra, rb);
}
std::vector<ll> minimum_costs(vector<int> H, vector<int> L, vector<int> R) {
int Q = L.size();
vector<ll> C(Q);
int N = 0;
for (int j = 0; j < Q; ++j) {
N = max(N, R[j]);
}
N++;
assert(N<=3000);
n = N;
for(int i=0; i<N; ++i){
update(i, H[i]);
}
for(int j=0; j<Q; ++j){
int l = L[j], r = R[j];
ll ans = 4e18;
for(int x=l; x<=r; ++x){
ll cur = 0;
for(int i=l; i<=r; ++i){
cur += T.query(i, x);
}
ans = min(ans, cur);
}
C[j] = ans;
}
return C;
}