Submission #538233

#TimeUsernameProblemLanguageResultExecution timeMemory
538233AdamGSPeru (RMI20_peru)C++17
49 / 100
614 ms88448 KiB
#include "peru.h" #include<bits/stdc++.h> using namespace std; typedef long long ll; #define rep(a, b) for(int a = 0; a < (b); ++a) #define st first #define nd second #define pb push_back #define all(a) a.begin(), a.end() const ll MOD=1e9+7, LIM=25e5+7, INF=1e18+7; ll dp[LIM], tr[4*LIM], trm[4*LIM], N=1, li; vector<pair<ll,int>>V; ll cnt(int l, int r) { l+=N; r+=N; ll ans=max(tr[l], tr[r]); while(l/2!=r/2) { if(l%2==0) ans=max(ans, tr[l+1]); if(r%2==1) ans=max(ans, tr[r-1]); l/=2; r/=2; } return ans; } ll cnt2(int l, int r) { if(l>r) return INF; l+=N; r+=N; ll ans=min(trm[l], trm[r]); while(l/2!=r/2) { if(l%2==0) ans=min(ans, trm[l+1]); if(r%2==1) ans=min(ans, trm[r-1]); l/=2; r/=2; } return ans; } void upd(int v, ll x) { v+=N; trm[v]=x; v/=2; while(v) { trm[v]=min(trm[2*v], trm[2*v+1]); v/=2; } } int solve(int n, int k, int* v){ while(N<n) N*=2; rep(i, n) tr[N+i]=v[i]; for(int i=N-1; i>=0; --i) tr[i]=max(tr[2*i], tr[2*i+1]); rep(i, k) { dp[i]=cnt(0, i); while(V.size() && v[i]>=V.back().st) { V.pop_back(); li=min(li, (long long)V.size()); } if(V.size()) upd(V.size(), v[i]+dp[V.back().nd]); V.pb({v[i], i}); } for(int i=k; i<n; ++i) { while(V.size() && v[i]>=V.back().st) { V.pop_back(); li=min(li, (long long)V.size()); } if(V.size()) upd(V.size(), v[i]+dp[V.back().nd]); V.pb({v[i], i}); dp[i]=dp[i-k]+cnt(i-k+1, i); while(li<V.size() && V[li].nd<=i-k) ++li; dp[i]=min(dp[i], cnt2(li+1, V.size()-1)); } ll ans=0; rep(i, n) ans=(ans*23+dp[i])%MOD; return ans; }

Compilation message (stderr)

peru.cpp: In function 'int solve(int, int, int*)':
peru.cpp:64:13: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::pair<long long int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   64 |     while(li<V.size() && V[li].nd<=i-k) ++li;
      |           ~~^~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...