# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1062713 |
2024-08-17T09:59:54 Z |
TimDee |
Peru (RMI20_peru) |
C++17 |
|
1 ms |
2396 KB |
#include "peru.h"
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("popcnt,avx2")
using ll = long long;
const int N=25e5+5;
ll dp[N];
int solve(int n, int k, int* v){
const int mod = 1e9+7;
#define int long long
#define forn(i,n) for(int i=0; i<(n); ++i)
#define pb push_back
#define pi pair<int,int>
#define f first
#define s second
deque<pi> s;
deque<pi> z;
ll ans=0;
int ptr=0;
int R=0;
forn(i,n) {
while (s.size() && s[0].s<=i-k) {
s.pop_front();
--ptr;
}
while (z.size() && z[0].s<=i-k) z.pop_front();
while (s.size() && s.back().f < v[i]) {
s.pop_back();
ptr=min(ptr,(int)s.size());
}
if (s.size()) {
while (z.size() && z.back().s > s.back().s) z.pop_back();
if (s.back().s<i-1) z.push_back({dp[s.back().s]+v[i],s.back().s+1});
} else {
while (z.size()) z.pop_back();
if (k>1 && i-k>=0) z.push_back({dp[i-k]+v[i],i-k+1});
}
s.pb({v[i],i});
if (i-k>=0) {
R=max(R,i-k);
ptr=max(ptr,0ll);
while (dp[R]==dp[R+1]) ++R;
while (s[ptr].s<=R) ++ptr;
if (z.size()) if (dp[R]+s[ptr].f < z.front().f) z.push_front({dp[R]+s[ptr].f,R});
}
dp[i]=s[0].f;
if (i-k>=0) dp[i]+=dp[i-k];
if (i) dp[i]=min(dp[i],dp[i-1]+v[i]);
if (z.size()) dp[i] = min(dp[i],z[0].f);
if (i) {
while (z.size() && z.back().f > dp[i-1]+v[i]) z.pop_back();
z.pb({dp[i-1]+v[i],i});
} else {
while (z.size() && z.back().f > v[i]) z.pop_back();
z.pb({v[i],i});
}
ans=(ans*23)%mod;
ans=(ans+dp[i])%mod;
}
return ans;
#undef int
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |