# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
490915 |
2021-11-29T17:58:07 Z |
ETK |
Peru (RMI20_peru) |
C++14 |
|
515 ms |
72524 KB |
//GOODTEK!!!
#include <bits/stdc++.h>
#include "peru.h"
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define pii pair<int,int>
#define vi vector<int>
#define fi first
#define se second
#define pb push_back
#define ALL(x) x.begin(),x.end()
#define ll long long
using namespace std;
inline ll read(){
ll x=0,f=1;char ch=getchar();
while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;
}
const int N=2500005,P=1e9+7;
ll f[N],pw[N],a[N];
deque<int>q;
multiset<ll> S;
int solve(int n,int k,int *v){
ll ans=0;
rep(i,1,n)a[i]=v[i-1];
pw[0]=1;
rep(i,1,n)pw[i]=pw[i-1]*23%P;
//滑动窗口顺带一个multiset维护目前最小值
rep(i,1,n){
while(q.size()&&q.front()<i-k+1){
ll x=f[q.front()];
q.pop_front();
if(q.size()){
x+=a[q.front()];
auto it=S.find(x);
S.erase(it);
}
}
while(q.size() && a[q.back()] <= a[i]) {
ll x = a[q.back()];
q.pop_back();
if(q.size()){
x += f[q.back()];
auto it = S.find(x);
S.erase(it);
}
}
if(q.size())S.insert(a[i] + f[q.back()]);
q.push_back(i);
if(S.size()) {
f[i] = min((ll)(*S.begin()), f[max(i - k, 0)] + a[q.front()]);
} else f[i] = f[max(0, i - k)] + a[q.front()];
ans+=(f[i]%P)*pw[n-i]%P;
ans%=P;
}
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 |
0 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 |
3 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 |
0 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 |
3 ms |
340 KB |
Output is correct |
15 |
Correct |
84 ms |
11424 KB |
Output is correct |
16 |
Correct |
70 ms |
11416 KB |
Output is correct |
17 |
Correct |
67 ms |
11356 KB |
Output is correct |
18 |
Correct |
59 ms |
11344 KB |
Output is correct |
19 |
Correct |
45 ms |
11304 KB |
Output is correct |
20 |
Correct |
44 ms |
11340 KB |
Output is correct |
21 |
Correct |
63 ms |
11408 KB |
Output is correct |
22 |
Correct |
83 ms |
11460 KB |
Output is correct |
23 |
Correct |
63 ms |
11468 KB |
Output is correct |
24 |
Correct |
64 ms |
11428 KB |
Output is correct |
25 |
Correct |
64 ms |
11384 KB |
Output is correct |
26 |
Correct |
62 ms |
11400 KB |
Output is correct |
27 |
Correct |
75 ms |
11344 KB |
Output is correct |
28 |
Correct |
64 ms |
11480 KB |
Output is correct |
29 |
Correct |
58 ms |
11620 KB |
Output is correct |
30 |
Correct |
67 ms |
11452 KB |
Output is correct |
31 |
Correct |
67 ms |
11392 KB |
Output is correct |
32 |
Correct |
70 ms |
11424 KB |
Output is correct |
33 |
Correct |
69 ms |
11376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
84 ms |
11424 KB |
Output is correct |
2 |
Correct |
70 ms |
11416 KB |
Output is correct |
3 |
Correct |
67 ms |
11356 KB |
Output is correct |
4 |
Correct |
59 ms |
11344 KB |
Output is correct |
5 |
Correct |
45 ms |
11304 KB |
Output is correct |
6 |
Correct |
44 ms |
11340 KB |
Output is correct |
7 |
Correct |
63 ms |
11408 KB |
Output is correct |
8 |
Correct |
83 ms |
11460 KB |
Output is correct |
9 |
Correct |
63 ms |
11468 KB |
Output is correct |
10 |
Correct |
64 ms |
11428 KB |
Output is correct |
11 |
Correct |
64 ms |
11384 KB |
Output is correct |
12 |
Correct |
62 ms |
11400 KB |
Output is correct |
13 |
Correct |
75 ms |
11344 KB |
Output is correct |
14 |
Correct |
64 ms |
11480 KB |
Output is correct |
15 |
Correct |
58 ms |
11620 KB |
Output is correct |
16 |
Correct |
67 ms |
11452 KB |
Output is correct |
17 |
Correct |
67 ms |
11392 KB |
Output is correct |
18 |
Correct |
70 ms |
11424 KB |
Output is correct |
19 |
Correct |
69 ms |
11376 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 |
0 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 |
3 ms |
340 KB |
Output is correct |
34 |
Correct |
474 ms |
68888 KB |
Output is correct |
35 |
Correct |
442 ms |
69316 KB |
Output is correct |
36 |
Correct |
456 ms |
69160 KB |
Output is correct |
37 |
Correct |
432 ms |
69132 KB |
Output is correct |
38 |
Correct |
427 ms |
69180 KB |
Output is correct |
39 |
Correct |
421 ms |
69296 KB |
Output is correct |
40 |
Correct |
476 ms |
69184 KB |
Output is correct |
41 |
Correct |
437 ms |
69068 KB |
Output is correct |
42 |
Correct |
437 ms |
69240 KB |
Output is correct |
43 |
Correct |
154 ms |
28124 KB |
Output is correct |
44 |
Correct |
159 ms |
41476 KB |
Output is correct |
45 |
Correct |
226 ms |
41536 KB |
Output is correct |
46 |
Correct |
162 ms |
41540 KB |
Output is correct |
47 |
Correct |
408 ms |
69312 KB |
Output is correct |
48 |
Correct |
438 ms |
69508 KB |
Output is correct |
49 |
Correct |
448 ms |
69788 KB |
Output is correct |
50 |
Correct |
455 ms |
70868 KB |
Output is correct |
51 |
Correct |
515 ms |
70352 KB |
Output is correct |
52 |
Correct |
418 ms |
72524 KB |
Output is correct |
53 |
Correct |
425 ms |
71220 KB |
Output is correct |
54 |
Correct |
412 ms |
69068 KB |
Output is correct |
55 |
Correct |
409 ms |
69056 KB |
Output is correct |
56 |
Correct |
406 ms |
69064 KB |
Output is correct |
57 |
Correct |
443 ms |
69260 KB |
Output is correct |
58 |
Correct |
393 ms |
69144 KB |
Output is correct |
59 |
Correct |
405 ms |
69160 KB |
Output is correct |
60 |
Correct |
401 ms |
69068 KB |
Output is correct |
61 |
Correct |
443 ms |
69460 KB |
Output is correct |
62 |
Correct |
453 ms |
69480 KB |
Output is correct |
63 |
Correct |
440 ms |
69216 KB |
Output is correct |