Submission #1054803

#TimeUsernameProblemLanguageResultExecution timeMemory
1054803Ahmed57Meetings (IOI18_meetings)C++17
19 / 100
5562 ms786432 KiB
#include "bits/stdc++.h" using namespace std; #define int long long int arr[100001]; pair<int,int> seg[400001]; int n ,q; void build(int p,int l,int r){ if(l==r){ seg[p] = {arr[l],l}; return ; } int md = (l+r)/2; build(p*2,l,md); build(p*2+1,md+1,r); seg[p] = max(seg[p*2],seg[p*2+1]); } pair<int,int> query(int p,int l,int r,int lq,int rq){ if(l>=lq&&r<=rq)return seg[p]; if(r<lq||l>rq)return {0,0}; int md = (l+r)/2; return max(query(p*2,l,md,lq,rq),query(p*2+1,md+1,r,lq,rq)); } map<pair<int,int>,int> dp; int solve(int l,int r){ if(l>r)return 0; if(dp.find(make_pair(l,r))!=dp.end())return dp[{l,r}]; int ind = query(1,0,n-1,l,r).second; return dp[{l,r}] = min(solve(l,ind-1)+(r-ind+1)*arr[ind],solve(ind+1,r)+(ind-l+1)*arr[ind]); } vector<long long> minimum_costs(vector<int32_t> H, vector<int32_t> L, vector<int32_t> R){ n = H.size(); q = L.size(); for(int i = 0;i<n;i++){ arr[i] = H[i]; } build(1,0,n-1); vector<long long> an; for(int i = 0;i<q;i++){ an.push_back(solve(L[i],R[i])); } return an; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...