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>
#ifndef ARTHUR_LOCAL
#include "meetings.h"
#endif
using namespace std;
using ll = long long;
const int p2 = 2*4096;
const int MAXN = 5000;
int max_segtree[p2+p2];
ll sum_arr[MAXN][MAXN+1];
int RMQ(int l, int r)
{
l += p2;
r += p2;
if(l>r) swap(l,r);
int ans=0;
while(l<=r)
{
if(l%2 == 1) ans=max(ans,max_segtree[l++]);
if(r%2 == 0) ans=max(ans,max_segtree[r--]);
l/=2;
r/=2;
}
return ans;
}
vector<ll> minimum_costs(vector<int> H, vector<int> L, vector<int> R)
{
// int Q = L.size();
// std::vector<long long> C(Q);
// for (int j = 0; j < Q; ++j) {
// C[j] = H[L[j]];
// }
// return C;
int q = L.size();
int n = H.size();
for(int i=0; i<n; i++)
{
max_segtree[i+p2]=H[i];
}
for(int i=p2-1; i>=1; i--)
{
max_segtree[i]=max(max_segtree[i+i],max_segtree[i+i+1]);
}
for(int i=0; i<n; i++)
{
for(int j=0; j<n; j++)
{
// sum_segtree[i][j+p2]=ll(RMQ(i,j));
sum_arr[i][j+1] = sum_arr[i][j] + ll(RMQ(i,j));
}
}
vector<ll> ans;
for(int i=0; i<q; i++)
{
ll cur = 1e18;
for(int j=L[i]; j<=R[i]; j++)
{
cur = min(cur, sum_arr[j][R[i]+1] - sum_arr[j][L[i]]);
//cout << i << " " << j << " " << query(i,L[i],R[i]) << endl;
}
ans.push_back(cur);
}
return ans;
}
#ifdef ARTHUR_LOCAL
int main()
{
for(auto e:minimum_costs({2,4,3,5},{0,1},{2,3}))
{
cout << e << endl;
}
}
#endif
# | 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... |