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;
typedef long long lo;
typedef pair< lo,lo > PII;
#define fi first
#define se second
#define mp make_pair
#define endl "\n"
#define pb push_back
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR for(int i=1;i<=n;i++)
#define mid ((start+end)/2)
#define ort ((bas+son)/2)
const lo inf = 1000000000000000000;
const lo KOK = 100000;
const lo LOG = 30;
const lo li = 5003;
const lo mod = 1000000007;
lo n,m,b[li],a[li][li],k,flag,t,ind;
lo cev;
map<int,lo> tree[li];
string s;
inline void build(int node,int start,int end){
if(start==end){tree[ind][node]=a[ind][start-1];return ;}
build(node*2,start,mid),build(node*2+1,mid+1,end);
tree[ind][node]=tree[ind][node*2]+tree[ind][node*2+1];
}
inline lo query(int node,int start,int end,int l,int r){
if(start>end || start>r || end<l)return 0;
if(start>=l && end<=r){return tree[ind][node];}
return query(node*2,start,mid,l,r)+query(node*2+1,mid+1,end,l,r);
}
std::vector<long long> minimum_costs(vector<int> h,vector<int> l,vector<int> r) {
t = (int)l.size();
n=(int)h.size();
for(int i=0;i<n;i++){
int mx=0;
for(int j=i;j>=0;j--){
mx=max(mx,h[j]);
a[i][j]=mx;
}
mx=0;
for(int j=i;j<n;j++){
mx=max(mx,h[j]);
a[i][j]=mx;
}
}
for(int i=0;i<n;i++){
ind=i;
build(1,1,n);
}
vector<lo> v;
for(int i=0;i<t;i++){
cev=inf;
for(int j=l[i];j<=r[i];j++){
ind=j;
lo at=0,at1=0;
if(l[i]+1<=j+1 && l[i]+1<=n)at=query(1,1,n,l[i]+1,min((lo)n,(lo)j+1));
if(j+2<=n && j+2<=r[i]+1)at1=query(1,1,n,j+2,min((lo)n,(lo)r[i]+1));
cev=min(cev,at+at1);
}
v.pb(cev);
}
return v;
}
# | 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... |