# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
405917 |
2021-05-17T04:05:02 Z |
Drew_ |
Peru (RMI20_peru) |
C++17 |
|
600 ms |
35208 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> 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)));
//cerr << "> " << pq.top() << " " << (pending.empty() ? -1 : pending.top()) << '\n';
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;
}
/*
for (int i = 0; i < n; ++i)
{
dp[i] = 1e18;
int mx = 0;
for (int j = i; j >= max(0, i-k+1); --j)
{
mx = max(mx, v[j]);
dp[i] = min(dp[i], mx + (j ? dp[j-1] : 0));
}
}
*/
# |
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 |
5396 KB |
Output is correct |
16 |
Correct |
101 ms |
5524 KB |
Output is correct |
17 |
Correct |
89 ms |
6416 KB |
Output is correct |
18 |
Correct |
122 ms |
5072 KB |
Output is correct |
19 |
Correct |
134 ms |
5080 KB |
Output is correct |
20 |
Correct |
139 ms |
5072 KB |
Output is correct |
21 |
Correct |
103 ms |
5812 KB |
Output is correct |
22 |
Correct |
98 ms |
6372 KB |
Output is correct |
23 |
Correct |
114 ms |
6316 KB |
Output is correct |
24 |
Correct |
84 ms |
7380 KB |
Output is correct |
25 |
Correct |
91 ms |
7448 KB |
Output is correct |
26 |
Correct |
102 ms |
5820 KB |
Output is correct |
27 |
Correct |
109 ms |
5360 KB |
Output is correct |
28 |
Correct |
115 ms |
5352 KB |
Output is correct |
29 |
Correct |
116 ms |
5488 KB |
Output is correct |
30 |
Correct |
107 ms |
5772 KB |
Output is correct |
31 |
Correct |
98 ms |
6716 KB |
Output is correct |
32 |
Correct |
108 ms |
5512 KB |
Output is correct |
33 |
Correct |
82 ms |
6984 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
110 ms |
5396 KB |
Output is correct |
2 |
Correct |
101 ms |
5524 KB |
Output is correct |
3 |
Correct |
89 ms |
6416 KB |
Output is correct |
4 |
Correct |
122 ms |
5072 KB |
Output is correct |
5 |
Correct |
134 ms |
5080 KB |
Output is correct |
6 |
Correct |
139 ms |
5072 KB |
Output is correct |
7 |
Correct |
103 ms |
5812 KB |
Output is correct |
8 |
Correct |
98 ms |
6372 KB |
Output is correct |
9 |
Correct |
114 ms |
6316 KB |
Output is correct |
10 |
Correct |
84 ms |
7380 KB |
Output is correct |
11 |
Correct |
91 ms |
7448 KB |
Output is correct |
12 |
Correct |
102 ms |
5820 KB |
Output is correct |
13 |
Correct |
109 ms |
5360 KB |
Output is correct |
14 |
Correct |
115 ms |
5352 KB |
Output is correct |
15 |
Correct |
116 ms |
5488 KB |
Output is correct |
16 |
Correct |
107 ms |
5772 KB |
Output is correct |
17 |
Correct |
98 ms |
6716 KB |
Output is correct |
18 |
Correct |
108 ms |
5512 KB |
Output is correct |
19 |
Correct |
82 ms |
6984 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 |
639 ms |
35208 KB |
Time limit exceeded |
35 |
Halted |
0 ms |
0 KB |
- |