# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
401521 |
2021-05-10T12:53:45 Z |
Drew_ |
Peru (RMI20_peru) |
C++14 |
|
600 ms |
35608 KB |
#include "peru.h"
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")
#define mp make_pair
#define ll long long
#define ii pair<int, int>
#define pl pair<ll, ll>
#define f1 first
#define s2 second
const int MAX = 25e5 + 7;
const int mod = 1e9 + 7;
inline int add(ll x, ll y) { return (int)((x + y) % mod); }
inline int mul(ll x, ll y) { return (int)((x * y) % mod); }
struct Item {int mx, l, r; };
ll dp[MAX];
static int dq_l = 1, dq_r = 0;
Item dq[MAX];
int solve(int n, int k, int* v){
priority_queue<ll, vector<ll>, greater<ll>> pq, pending;
dp[0] = v[0];
dq[++dq_r] = {v[0], 0, 0};
pq.push(v[0]);
for (int i = 1; i < n; ++i)
{
//remove the front
if (dq_l <= dq_r && dq[dq_l].l <= i-k)
{
//int mx = dq[dq_l].mx, l = dq[dq_l].mx, r = dq[dq_l].r;
auto [mx, l, r] = dq[dq_l];
dq_l++;
pending.push(mx + (l ? dp[l-1] : 0));
if (r > i-k)
{
dq[--dq_l] = {mx, i-k+1, r};
pq.push(mx + (i-k+1 ? dp[i-k] : 0));
}
}
int cur_l = i, cur_r = i;
while (dq_l <= dq_r && dq[dq_r].mx <= v[i])
{
//int mx = dq[dq_r].mx, l = dq[dq_r].l, r = dq[dq_r].r;
auto [mx, l, r] = dq[dq_r];
dq_r--;
pending.push(mx + (l ? dp[l-1] : 0));
cur_l = l;
}
dq[++dq_r] = {v[i], cur_l, cur_r};
pq.push(v[i] + (cur_l ? dp[cur_l-1] : 0));
while (!pending.empty())
{
if (pq.top() > pending.top())
pending.pop();
else if (pq.top() < pending.top())
break;
else pq.pop(), pending.pop();
}
dp[i] = pq.top();
}
int pwr = 1, ans = 0;
for (int i = n-1; i >= 0; --i)
ans = add(ans, mul(dp[i]%mod, pwr)), pwr = mul(pwr, 23);
return ans;
}
Compilation message
peru.cpp: In function 'int solve(int, int, int*)':
peru.cpp:39:9: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
39 | auto [mx, l, r] = dq[dq_l];
| ^
peru.cpp:54:9: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
54 | auto [mx, l, r] = dq[dq_r];
| ^
# |
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 |
110 ms |
5440 KB |
Output is correct |
16 |
Correct |
112 ms |
5564 KB |
Output is correct |
17 |
Correct |
119 ms |
6396 KB |
Output is correct |
18 |
Correct |
138 ms |
5180 KB |
Output is correct |
19 |
Correct |
133 ms |
5136 KB |
Output is correct |
20 |
Correct |
138 ms |
5568 KB |
Output is correct |
21 |
Correct |
98 ms |
6188 KB |
Output is correct |
22 |
Correct |
102 ms |
6856 KB |
Output is correct |
23 |
Correct |
108 ms |
6640 KB |
Output is correct |
24 |
Correct |
88 ms |
8036 KB |
Output is correct |
25 |
Correct |
89 ms |
7788 KB |
Output is correct |
26 |
Correct |
98 ms |
6172 KB |
Output is correct |
27 |
Correct |
115 ms |
5376 KB |
Output is correct |
28 |
Correct |
122 ms |
5676 KB |
Output is correct |
29 |
Correct |
117 ms |
6084 KB |
Output is correct |
30 |
Correct |
105 ms |
6272 KB |
Output is correct |
31 |
Correct |
86 ms |
7144 KB |
Output is correct |
32 |
Correct |
136 ms |
6064 KB |
Output is correct |
33 |
Correct |
96 ms |
7504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
110 ms |
5440 KB |
Output is correct |
2 |
Correct |
112 ms |
5564 KB |
Output is correct |
3 |
Correct |
119 ms |
6396 KB |
Output is correct |
4 |
Correct |
138 ms |
5180 KB |
Output is correct |
5 |
Correct |
133 ms |
5136 KB |
Output is correct |
6 |
Correct |
138 ms |
5568 KB |
Output is correct |
7 |
Correct |
98 ms |
6188 KB |
Output is correct |
8 |
Correct |
102 ms |
6856 KB |
Output is correct |
9 |
Correct |
108 ms |
6640 KB |
Output is correct |
10 |
Correct |
88 ms |
8036 KB |
Output is correct |
11 |
Correct |
89 ms |
7788 KB |
Output is correct |
12 |
Correct |
98 ms |
6172 KB |
Output is correct |
13 |
Correct |
115 ms |
5376 KB |
Output is correct |
14 |
Correct |
122 ms |
5676 KB |
Output is correct |
15 |
Correct |
117 ms |
6084 KB |
Output is correct |
16 |
Correct |
105 ms |
6272 KB |
Output is correct |
17 |
Correct |
86 ms |
7144 KB |
Output is correct |
18 |
Correct |
136 ms |
6064 KB |
Output is correct |
19 |
Correct |
96 ms |
7504 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 |
666 ms |
35608 KB |
Time limit exceeded |
35 |
Halted |
0 ms |
0 KB |
- |