# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
945020 | itslq | Meetings (IOI18_meetings) | C++17 | 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 "meetings.h"
#include <bits/stdc++.h>
using namespace std;
#define int long long
vector<int> A;
struct node {
int l, r, m, v;
node *lc, *rc;
node(int _l, int _r): l(_l), r(_r) {
m = (l + r) >> 1;
if (l == r) {
v = A[l];
} else {
lc = new node(l, m);
rc = new node(m + 1, r);
v = max(lc -> v, rc -> v);
}
}
int query(int _l, int _r) {
if (l == _l && r == _r) {
return v;
} else if (_r <= m) {
return lc -> query(_l, _r);
} else if (_l > m) {
return rc -> query(_l, _r);
} else {
return max(lc -> query(_l, m), rc -> query(m + 1, _r));
}
}
} *root;
std::vector<long long> minimum_costs(std::vector<int> H, std::vector<int> L,
std::vector<int> R) {
int N = H.size();
int Q = L.size();
int S, T;
vector<int> ans;
A = H;
root = new node(1, N);
for (int i = 0; i < Q; i++) {
T = LLONG_MAX;
for (int j = L[i]; j < R[i]; j++) {
S = 0;
for (int k = L[i]; k < j; k++) S += root -> query(k, j);
for (int k = j; k <= R[i]; k++) S += root -> query(j, k);
T = min(T, S);
}
ans.push_back(T);
}
return ans;
}