Submission #171935

#TimeUsernameProblemLanguageResultExecution timeMemory
171935DeD_TihoNK blocks (IZhO14_blocks)C++14
100 / 100
459 ms6644 KiB
#pragma GCC optimize ("O3") #include<bits/stdc++.h> #include<ext/pb_ds/assoc_container.hpp> #include<ext/pb_ds/tree_policy.hpp> #define ff first #define ss second #define pb push_back #define mp make_pair #define ll long long #define ld long double #define endl '\n' #define all(a) a.begin(),a.end() #define ull unsigned long long #define y1 yaumru #define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); #define iter set< pair<int,int> >::iterator #define iter1 set< pair< int,pair<int,int> > >::iterator #define int long long using namespace std; using namespace __gnu_pbds; template<class T> using ordered_set=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>; template<class T> using ordered_multiset=tree<T,null_type,less_equal<T>,rb_tree_tag,tree_order_statistics_node_update>; mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); mt19937_64 rnd1(chrono::steady_clock::now().time_since_epoch().count()); //find_by_order //order_of_key const int N=1e5+7; const int inf=1e18+1e9; const int mod=1e9+7; const ld eps=1e-9; int a[N]; int dp[N]; int dp1[N]; int t[N*4]; int ob[N*4]; void push(int v,int l,int r) { if (ob[v]){ t[v]+=ob[v]; if (l!=r){ ob[v+v]+=ob[v]; ob[v+v+1]+=ob[v]; } ob[v]=0; } } void update(int v,int l,int r,int l1,int r1,int x) { push(v,l,r); if (l>r1 || r<l1)return; if (l>=l1 && r<=r1){ ob[v]+=x; push(v,l,r); return; } int mid=(l+r)/2; update(v+v,l,mid,l1,r1,x); update(v+v+1,mid+1,r,l1,r1,x); t[v]=min(t[v+v],t[v+v+1]); } int get(int v,int l,int r,int l1,int r1) { push(v,l,r); if (l>r1 || r<l1)return inf; if (l>=l1 && r<=r1){ return t[v]; } int mid=(l+r)/2; return min(get(v+v,l,mid,l1,r1),get(v+v+1,mid+1,r,l1,r1)); } main () { ios; int n,k; cin>>n>>k; for (int i=1;i<=n;++i){ cin>>a[i]; } int mx=0; dp[0]=inf; for (int i=1;i<=n;++i){ mx=max(mx,a[i]); dp[i]=mx; } for (int tt=2;tt<=k;++tt){ vector< pair< pair<int,int>,pair<int,int> > >c; c.pb({{inf,inf},{inf,0}}); dp1[0]=inf; for (int i=1;i<=n;++i){ c.pb({{0,dp[i-1]},{dp[i-1],i}}); int cur=inf; int r=i; while(a[i]>=c.back().ff.ff){ int pos=c.back().ss.ss; int res=c.back().ff.ss; res+=a[i]-c.back().ff.ff; cur=min(cur,res); c.pop_back(); r=pos; } int l=min(cur,c.back().ss.ff); dp1[i]=l; c.pb({{a[i],cur},{l,r}}); } for (int i=0;i<=n;++i){ dp[i]=dp1[i]; } } cout<<dp[n]<<endl; }

Compilation message (stderr)

blocks.cpp:83:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main ()
       ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...