#include<bits/stdc++.h>
#include<fstream>
using namespace std;
#define sz(a) (int)a.size()
#define ALL(v) v.begin(), v.end()
#define ALLR(v) v.rbegin(), v.rend()
#define ll long long
#define pb push_back
#define forr(i, a, b) for(int i = a; i < b; i++)
#define dorr(i, a, b) for(int i = a; i >= b; i--)
#define ld long double
#define vt vector
#include<fstream>
#define fi first
#define se second
#define pll pair<ll, ll>
#define pii pair<int, int>
#define mpp make_pair
#include<iostream>
#include "peru.h"
using namespace std;
const int mxn = 4e5 + 5;
const ll mod = 1e9 + 7, inf = 1e18;
ll a[mxn + 1];
ll dp[mxn + 1], pw[mxn + 1];
ll st[4 * mxn + 1], lz[4 * mxn + 1];
void push(int nd){
ll &v = lz[nd];
lz[nd << 1] += v; lz[nd << 1 | 1] += v; st[nd << 1] += v; st[nd << 1 | 1] += v;
v = 0;
}
void upd(int nd, int l, int r, int ql, int qr, ll v){
//if(nd == 1)cout << ql << " " << qr << " " << v << "\n";
if(ql > r || qr < l)return;
if(ql <= l && qr >= r){
st[nd] += v; lz[nd] += v; return;
}
int mid = (l + r) >> 1;
push(nd);
upd(nd << 1, l, mid, ql, qr, v); upd(nd << 1 | 1, mid + 1, r, ql, qr, v);
st[nd] = min(st[nd << 1], st[nd << 1 | 1]);
}
ll get(int nd, int l, int r, int ql, int qr){
if(ql > r || qr < l)return(inf);
if(ql <= l && qr >= r)return(st[nd]);
int mid = (l + r) >> 1;
push(nd);
return(min(get(nd << 1, l, mid, ql, qr), get(nd << 1 | 1, mid + 1, r, ql, qr)));
}
int solve(int n, int k, int* v){
pw[0] = 1;
for(int i = 1; i < n; i++)pw[i] = (pw[i - 1] * 23) % mod;
for(int i = 1; i <= n; i++)a[i] = v[i - 1];
deque<pair<int, int>>dq;
ll ans = 0;
for(int i = 1; i <= n; i++){
int last = i - 2;
while(sz(dq) && dq.back().se <= a[i]){
upd(1, 0, n, dq.back().fi - 1, last, a[i] - dq.back().se); last = dq.back().fi - 2; dq.pop_back();
}
dq.pb(mpp(last + 2, a[i]));
upd(1, 0, n, i - 1, i - 1, a[i]);
dp[i] = get(1, 0, n, max(i - k, 0), i - 1);
upd(1, 0, n, i, i, dp[i]);
ans = (ans + (dp[i] % mod) * pw[n - i]) % mod;
}
return(ans);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
10588 KB |
Output is correct |
2 |
Correct |
2 ms |
10712 KB |
Output is correct |
3 |
Correct |
2 ms |
10588 KB |
Output is correct |
4 |
Correct |
3 ms |
10588 KB |
Output is correct |
5 |
Correct |
3 ms |
10588 KB |
Output is correct |
6 |
Correct |
3 ms |
10588 KB |
Output is correct |
7 |
Correct |
2 ms |
10584 KB |
Output is correct |
8 |
Correct |
2 ms |
10588 KB |
Output is correct |
9 |
Correct |
2 ms |
10588 KB |
Output is correct |
10 |
Correct |
2 ms |
10584 KB |
Output is correct |
11 |
Correct |
3 ms |
10588 KB |
Output is correct |
12 |
Correct |
3 ms |
10588 KB |
Output is correct |
13 |
Correct |
3 ms |
10588 KB |
Output is correct |
14 |
Correct |
3 ms |
10584 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
10588 KB |
Output is correct |
2 |
Correct |
2 ms |
10712 KB |
Output is correct |
3 |
Correct |
2 ms |
10588 KB |
Output is correct |
4 |
Correct |
3 ms |
10588 KB |
Output is correct |
5 |
Correct |
3 ms |
10588 KB |
Output is correct |
6 |
Correct |
3 ms |
10588 KB |
Output is correct |
7 |
Correct |
2 ms |
10584 KB |
Output is correct |
8 |
Correct |
2 ms |
10588 KB |
Output is correct |
9 |
Correct |
2 ms |
10588 KB |
Output is correct |
10 |
Correct |
2 ms |
10584 KB |
Output is correct |
11 |
Correct |
3 ms |
10588 KB |
Output is correct |
12 |
Correct |
3 ms |
10588 KB |
Output is correct |
13 |
Correct |
3 ms |
10588 KB |
Output is correct |
14 |
Correct |
3 ms |
10584 KB |
Output is correct |
15 |
Correct |
316 ms |
35496 KB |
Output is correct |
16 |
Correct |
319 ms |
35668 KB |
Output is correct |
17 |
Correct |
307 ms |
35648 KB |
Output is correct |
18 |
Correct |
309 ms |
35584 KB |
Output is correct |
19 |
Correct |
316 ms |
35516 KB |
Output is correct |
20 |
Correct |
317 ms |
35416 KB |
Output is correct |
21 |
Correct |
302 ms |
35508 KB |
Output is correct |
22 |
Correct |
320 ms |
35768 KB |
Output is correct |
23 |
Correct |
306 ms |
35824 KB |
Output is correct |
24 |
Correct |
313 ms |
35520 KB |
Output is correct |
25 |
Correct |
311 ms |
35776 KB |
Output is correct |
26 |
Correct |
304 ms |
35644 KB |
Output is correct |
27 |
Correct |
310 ms |
35616 KB |
Output is correct |
28 |
Correct |
306 ms |
35704 KB |
Output is correct |
29 |
Correct |
322 ms |
35672 KB |
Output is correct |
30 |
Correct |
306 ms |
35500 KB |
Output is correct |
31 |
Correct |
357 ms |
35652 KB |
Output is correct |
32 |
Correct |
306 ms |
35664 KB |
Output is correct |
33 |
Correct |
297 ms |
35508 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
316 ms |
35496 KB |
Output is correct |
2 |
Correct |
319 ms |
35668 KB |
Output is correct |
3 |
Correct |
307 ms |
35648 KB |
Output is correct |
4 |
Correct |
309 ms |
35584 KB |
Output is correct |
5 |
Correct |
316 ms |
35516 KB |
Output is correct |
6 |
Correct |
317 ms |
35416 KB |
Output is correct |
7 |
Correct |
302 ms |
35508 KB |
Output is correct |
8 |
Correct |
320 ms |
35768 KB |
Output is correct |
9 |
Correct |
306 ms |
35824 KB |
Output is correct |
10 |
Correct |
313 ms |
35520 KB |
Output is correct |
11 |
Correct |
311 ms |
35776 KB |
Output is correct |
12 |
Correct |
304 ms |
35644 KB |
Output is correct |
13 |
Correct |
310 ms |
35616 KB |
Output is correct |
14 |
Correct |
306 ms |
35704 KB |
Output is correct |
15 |
Correct |
322 ms |
35672 KB |
Output is correct |
16 |
Correct |
306 ms |
35500 KB |
Output is correct |
17 |
Correct |
357 ms |
35652 KB |
Output is correct |
18 |
Correct |
306 ms |
35664 KB |
Output is correct |
19 |
Correct |
297 ms |
35508 KB |
Output is correct |
20 |
Correct |
2 ms |
10588 KB |
Output is correct |
21 |
Correct |
2 ms |
10712 KB |
Output is correct |
22 |
Correct |
2 ms |
10588 KB |
Output is correct |
23 |
Correct |
3 ms |
10588 KB |
Output is correct |
24 |
Correct |
3 ms |
10588 KB |
Output is correct |
25 |
Correct |
3 ms |
10588 KB |
Output is correct |
26 |
Correct |
2 ms |
10584 KB |
Output is correct |
27 |
Correct |
2 ms |
10588 KB |
Output is correct |
28 |
Correct |
2 ms |
10588 KB |
Output is correct |
29 |
Correct |
2 ms |
10584 KB |
Output is correct |
30 |
Correct |
3 ms |
10588 KB |
Output is correct |
31 |
Correct |
3 ms |
10588 KB |
Output is correct |
32 |
Correct |
3 ms |
10588 KB |
Output is correct |
33 |
Correct |
3 ms |
10584 KB |
Output is correct |
34 |
Runtime error |
65 ms |
63556 KB |
Execution killed with signal 11 |
35 |
Halted |
0 ms |
0 KB |
- |