Submission #587719

#TimeUsernameProblemLanguageResultExecution timeMemory
587719Koosha_mvMeetings (IOI18_meetings)C++14
0 / 100
5544 ms7380 KiB
#include "meetings.h" #include <bits/stdc++.h> using namespace std; #define dbgv(v) cout<<#v<<" = "; f(i,0,int(v.size())) cout<<v[i]<<" "; cout<<endl #define dbga(a,x,y) cout<<#a<<" = "; f(i,x,y) cout<<a[i]<<" "; cout<<endl #define erorp(x) cout<<#x<<"={"<<x.F<<" , "<<x.S<<"}"<<endl #define eror(x) cout<<#x<<'='<<(x)<<endl #define f_(i,a,b) for(int i=a;i>=b;i--) #define f(i,a,b) for(int i=a;i<b;i++) #define nb(x) __builtin_popcount(x) #define all(v) v.begin(),v.end() #define bit(n,k) (((n)>>(k))&1) #define Add(x,y) x=(x+y)%mod #define maxm(a,b) a=max(a,b) #define minm(a,b) a=min(a,b) #define lst(x) x[x.size()-1] #define sz(x) int(x.size()) #define mp make_pair #define ll long long #define pb push_back #define S second #define F first const int N=1e6+99,inf=1e9+99; int n,q,L[N],R[N]; ll res[N]; vector<int> H,A; vector<ll> ans; ll solve(vector<int> A){ //dbgv(A); vector<int> vec(1); ll sum=0; f(i,0,int(A.size())) res[i]=0; f(i,1,int(A.size())-1){ while(A[i]>=A[vec.back()]){ int x=vec.back(),y=x; vec.pop_back(); if(vec.size()) y=vec.back(); sum-=(x-y)*A[x]; } sum+=(i-vec.back())*A[i]; res[i]+=sum; vec.pb(i); } sum=0; vec.resize(1); vec[0]=A.size()-1; //dbga(res,0,int(A.size())); f_(i,int(A.size())-2,1){ while(A[i]>=A[vec.back()]){ int x=vec.back(),y=x; vec.pop_back(); if(vec.size()) y=vec.back(); sum-=(y-x)*A[x]; } sum+=(vec.back()-i)*A[i]; res[i]+=sum; vec.pb(i); } //dbga(res,0,int(A.size())); ll ans=1ll*N*inf; f(i,1,int(A.size())-1) minm(ans,res[i]-A[i]); //eror(ans); return ans; } vector<long long> minimum_costs(vector<int> _H,vector<int> L,vector<int> R){ q=L.size(),n=H.size(),H=_H; ans.resize(q); f(i,0,q){ A.clear(); A.pb(inf); f(j,L[i],R[i]+1) A.pb(H[j]); A.pb(inf); ans[i]=solve(A); } return ans; }
#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...