#include "meetings.h"
#include <bits/stdc++.h>
#define INF (1 << 30)
#define INFL (1LL << 60)
#define fi first
#define se second
#define ll long long
using namespace std;
const int MAXN = 7.5e5 + 11;
long long fl[MAXN], fr[MAXN];
vector<int> H;
vector<long long> calc(int l, int r){
vector<long long> res(r - l + 1);
vector<pair<int, int>> F;
long long cost = 0;
F.push_back({l - 1, INF});
for(int j = l; j <= r; j++){
while(H[j] >= F.back().se) cost -= (long long) (F.back().fi - F[F.size() - 2].fi) * F.back().se, F.pop_back();
F.push_back({j, H[j]}); cost += (long long) (F.back().fi - F[F.size() - 2].fi) * F.back().se;
res[j - l] = cost;
}
return res;
}
std::vector<long long> minimum_costs(std::vector<int> H, std::vector<int> L,
std::vector<int> R) {
::H = H;
int Q = L.size();
vector<ll> C(Q);
for(int i = 0; i < Q; i++){
int l = L[i], r = R[i];
vector<ll> a = calc(l, r);
reverse(::H.begin() + l, ::H.begin() + r + 1);
vector<ll> b = calc(l, r);
reverse(::H.begin() + l, ::H.begin() + r + 1);
reverse(b.begin(), b.end());
long long ans = INFL;
for(int i = 0; i <= r - l; i++){
ans = min(ans, a[i] + b[i] - H[l + i]);
}
C[i] = ans;
}
return C;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
2 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
320 KB |
Output is correct |
5 |
Correct |
2 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
320 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
316 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
2 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
320 KB |
Output is correct |
5 |
Correct |
2 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
320 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
316 KB |
Output is correct |
10 |
Correct |
233 ms |
676 KB |
Output is correct |
11 |
Correct |
737 ms |
692 KB |
Output is correct |
12 |
Correct |
237 ms |
800 KB |
Output is correct |
13 |
Correct |
734 ms |
724 KB |
Output is correct |
14 |
Correct |
203 ms |
692 KB |
Output is correct |
15 |
Correct |
205 ms |
692 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
3414 ms |
2500 KB |
Output is correct |
3 |
Execution timed out |
5518 ms |
8056 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
3414 ms |
2500 KB |
Output is correct |
3 |
Execution timed out |
5518 ms |
8056 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
2 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
320 KB |
Output is correct |
5 |
Correct |
2 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
320 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
316 KB |
Output is correct |
10 |
Correct |
233 ms |
676 KB |
Output is correct |
11 |
Correct |
737 ms |
692 KB |
Output is correct |
12 |
Correct |
237 ms |
800 KB |
Output is correct |
13 |
Correct |
734 ms |
724 KB |
Output is correct |
14 |
Correct |
203 ms |
692 KB |
Output is correct |
15 |
Correct |
205 ms |
692 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
3414 ms |
2500 KB |
Output is correct |
18 |
Execution timed out |
5518 ms |
8056 KB |
Time limit exceeded |
19 |
Halted |
0 ms |
0 KB |
- |