#include<bits/stdc++.h>
#include "peru.h"
using namespace std;
#define ll long long
#define pii pair<int,int>
#define f first
#define s second
#define endl "\n"
const int N = 25e5 + 5, mod = 1e9 + 7; //!
int t;
void add(int &a, int c) {
a += c;
if(a >= mod) a -= mod;
}
int solve(int n, int k, int *x) {
vector<int> a(n + 1), p(n + 1);
vector<ll> dp(n + 1);
for(int i = 0; i < n; i++) a[i + 1] = x[i];
deque<pii> st;
multiset<ll> s;
p[0] = 1;
for(int i = 1; i <= n - 1; i++) p[i] = (ll)p[i - 1] * 23 % mod;
int ans = 0;
for(int i = 1; i <= n; i++) {
if(st.size() && st.front().s < i - k + 1) {
pii x = st.front();
s.erase(s.find(dp[x.s - 1] + a[x.f]));
st.front().s++;
x.s++;
if(x.s> x.f) st.pop_front();
else {
s.insert(dp[x.s - 1] + a[x.f]);
}
}
int l = i;
while(st.size() && a[st.back().f] < a[i]) {
l = st.back().s;
s.erase(s.find(dp[l - 1] + a[st.back().f]));
st.pop_back();
}
st.push_back({i, l});
ll x = a[i] + dp[l - 1];
s.insert(x);
dp[i] = *s.begin();
add(ans, (ll)dp[i] % mod * p[n - i] % mod);
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
87 ms |
8284 KB |
Output is correct |
16 |
Correct |
88 ms |
8304 KB |
Output is correct |
17 |
Correct |
83 ms |
8276 KB |
Output is correct |
18 |
Correct |
60 ms |
8276 KB |
Output is correct |
19 |
Correct |
64 ms |
8276 KB |
Output is correct |
20 |
Correct |
65 ms |
8276 KB |
Output is correct |
21 |
Correct |
86 ms |
8308 KB |
Output is correct |
22 |
Correct |
94 ms |
8384 KB |
Output is correct |
23 |
Correct |
97 ms |
8312 KB |
Output is correct |
24 |
Correct |
85 ms |
8312 KB |
Output is correct |
25 |
Correct |
86 ms |
8276 KB |
Output is correct |
26 |
Correct |
93 ms |
8288 KB |
Output is correct |
27 |
Correct |
89 ms |
8228 KB |
Output is correct |
28 |
Correct |
93 ms |
8380 KB |
Output is correct |
29 |
Correct |
103 ms |
8564 KB |
Output is correct |
30 |
Correct |
90 ms |
8320 KB |
Output is correct |
31 |
Correct |
116 ms |
8208 KB |
Output is correct |
32 |
Correct |
94 ms |
8424 KB |
Output is correct |
33 |
Correct |
78 ms |
8276 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
87 ms |
8284 KB |
Output is correct |
2 |
Correct |
88 ms |
8304 KB |
Output is correct |
3 |
Correct |
83 ms |
8276 KB |
Output is correct |
4 |
Correct |
60 ms |
8276 KB |
Output is correct |
5 |
Correct |
64 ms |
8276 KB |
Output is correct |
6 |
Correct |
65 ms |
8276 KB |
Output is correct |
7 |
Correct |
86 ms |
8308 KB |
Output is correct |
8 |
Correct |
94 ms |
8384 KB |
Output is correct |
9 |
Correct |
97 ms |
8312 KB |
Output is correct |
10 |
Correct |
85 ms |
8312 KB |
Output is correct |
11 |
Correct |
86 ms |
8276 KB |
Output is correct |
12 |
Correct |
93 ms |
8288 KB |
Output is correct |
13 |
Correct |
89 ms |
8228 KB |
Output is correct |
14 |
Correct |
93 ms |
8380 KB |
Output is correct |
15 |
Correct |
103 ms |
8564 KB |
Output is correct |
16 |
Correct |
90 ms |
8320 KB |
Output is correct |
17 |
Correct |
116 ms |
8208 KB |
Output is correct |
18 |
Correct |
94 ms |
8424 KB |
Output is correct |
19 |
Correct |
78 ms |
8276 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
1 ms |
340 KB |
Output is correct |
34 |
Execution timed out |
643 ms |
49468 KB |
Time limit exceeded |
35 |
Halted |
0 ms |
0 KB |
- |