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>
#define ll long long
#define pb push_back
#define vi vector<int>
#define fi first
#define se second
#define local
#ifndef local
#include "meetings.h"
#endif
using namespace std;
int Q,n;
ll DD[5005][5005];
vector<ll> small(vi H,vi L,vi R) {
vector<ll> T(Q);
vector<int> e = H,WW(n);
sort(e.begin(),e.end());
map<int,int> mp;
int cnt = 0;
for (int i = 0; i < n; i++) {
if (i == 0 || e[i-1] != e[i]) {
mp[e[i]] = cnt;
WW[cnt] = e[i];
}
}
for (int i = 0; i < cnt; i++) {
int val = WW[cnt];
ll sum = 0;
for (int j = 0; j < n; j++) {
sum += max(H[j],val);
DD[i][j] = sum;
}
}
for (int i = 0; i < Q; i++) {
int l = L[i], r = R[i];
stack<ll> st;
ll ans = LLONG_MAX;
for (int x = l ; x <= r; x++) {
int id = mp[H[x]];
ll sum = DD[id][r] - (l ? DD[id][l-1] : 0);
ans = min(ans,sum);
}
T[i] = ans;
}
return T;
}
vector<ll> minimum_costs(vi H, vi L,vi R) {
n = H.size(); Q = L.size();
if (n <= 5000 && Q <= 5000) return small(H,L,R);
std::vector<long long> C(Q);
for (int j = 0; j < Q; ++j) {
C[j] = H[L[j]];
}
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... |