#include "peru.h"
#include <iostream>
#include <deque>
#include <queue>
#include <vector>
using namespace std;
constexpr int NMAX = 2500005;
constexpr int MOD = 1e9 + 7;
typedef long long LL;
typedef pair <LL, int> PLI;
int ans = 0;
LL dp[NMAX];
int val[NMAX];
int solve(int n, int k, int* v){
deque <int> D;
priority_queue <PLI, vector<PLI>, greater<PLI> > H;
for (int i = 0; i < n; ++ i ) {
while (!D.empty() && v[D.back()] < v[i]) {
val[D.back()] = -1;
D.pop_back();
}
while (!D.empty() && D.front() <= i - k) {
val[D.front()] = -1;
D.pop_front();
}
if (D.empty()) {
val[i] = (i-k < 0 ? 0 : dp[i-k]) + v[i];
H.push({val[i], i});
}
else {
val[i] = dp[D.back()] + v[i];
H.push({val[i], i});
}
if (!D.empty() && i - k >= 0) {
val[D.front()] = v[D.front()] + dp[i-k];
H.push({val[D.front()], D.front()});
}
D.push_back(i);
while (!H.empty() && val[H.top().second] != H.top().first)
H.pop();
if (!H.empty()) dp[i] = H.top().first;
else dp[i] = (i - k < 0 ? 0 : dp[i - k]) + v[i];
}
for (int i = 0; i < n; ++ i )
ans = (23LL * ans + dp[i] % MOD) % MOD;
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |