#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;
const int maxn=1e5+5, Log=17, pot=(1<<Log), maxk=105;
const int inf=1e9;
struct tournament{
int t[pot*2];
int mindp[pot*2];
int prop[pot*2];
tournament(){
for(int i=0; i<pot*2; i++){
t[i]=inf;
mindp[i]=inf;
}
}
void propagate(int x){
if(!prop[x]){
return;
}
t[x]=prop[x]+mindp[x];
if(x<pot){
prop[x*2]=prop[x];
prop[x*2+1]=prop[x];
}
prop[x]=0;
}
void update0(int x, int val){
mindp[x]=val;
for(x/=2; x>0; x/=2){
mindp[x]=min(mindp[x*2], mindp[x*2+1]);
}
}
void update(int x, int val){
t[x]=mindp[x]+val;
for(x/=2; x>0; x/=2){
propagate(x*2);
propagate(x*2+1);
t[x]=min(t[x*2], t[x*2+1]);
}
}
void update2(int L, int D, int x, int l, int d, int val){
propagate(x);
if(L>=l && D<=d){
update(x, val);
if(x<pot){
prop[x*2]=val;
prop[x*2+1]=val;
}
return;
}
if((L+D)/2>=l){
update2(L, (L+D)/2, x*2, l, d, val);
}
if((L+D)/2+1<=d){
update2((L+D)/2+1, D, x*2+1, l, d, val);
}
}
};
tournament T[maxk];
int n, k;
vector < pair < int, int > > v;
int main(){
scanf("%d%d", &n, &k);
int a;
int pos;
int maksi=0;
v.push_back({inf, 0});
for(int i=0; i<n; i++){
scanf("%d", &a);
maksi=max(maksi, a);
while(v.back().first<a){
v.pop_back();
}
pos=v.back().second;
v.push_back({a, i+1});
// cout << pos << endl;
T[1].update0(i+1+pot, maksi);
for(int j=2; j<=k; j++){
if(j>i+1){
break;
}
else{
// cout << "uso " << i << ' ' << j << endl;
T[j-1].update2(0, pot-1, 1, pos, i, a);
// cout << T[j-1].query(0, pot-1, 1, pos, i) << endl;
T[j].update0(i+pot+1, T[j-1].t[1]);
}
}
}
if(k==1){
printf("%d\n", maksi);
}
else{
printf("%d\n", T[k].mindp[n+pot]);
}
}
Compilation message
blocks.cpp: In function 'int main()':
blocks.cpp:73:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
73 | scanf("%d%d", &n, &k);
| ~~~~~^~~~~~~~~~~~~~~~
blocks.cpp:79:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
79 | scanf("%d", &a);
| ~~~~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
127 ms |
216388 KB |
Output is correct |
2 |
Correct |
119 ms |
216300 KB |
Output is correct |
3 |
Correct |
118 ms |
216368 KB |
Output is correct |
4 |
Correct |
118 ms |
216356 KB |
Output is correct |
5 |
Correct |
118 ms |
216292 KB |
Output is correct |
6 |
Correct |
120 ms |
216440 KB |
Output is correct |
7 |
Correct |
116 ms |
216316 KB |
Output is correct |
8 |
Correct |
118 ms |
216240 KB |
Output is correct |
9 |
Correct |
118 ms |
216340 KB |
Output is correct |
10 |
Correct |
118 ms |
216332 KB |
Output is correct |
11 |
Correct |
119 ms |
216384 KB |
Output is correct |
12 |
Correct |
118 ms |
216304 KB |
Output is correct |
13 |
Correct |
119 ms |
216388 KB |
Output is correct |
14 |
Correct |
120 ms |
216452 KB |
Output is correct |
15 |
Correct |
119 ms |
216352 KB |
Output is correct |
16 |
Correct |
121 ms |
216276 KB |
Output is correct |
17 |
Correct |
120 ms |
216232 KB |
Output is correct |
18 |
Correct |
120 ms |
216296 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
120 ms |
216356 KB |
Output is correct |
2 |
Correct |
120 ms |
216340 KB |
Output is correct |
3 |
Correct |
118 ms |
216236 KB |
Output is correct |
4 |
Correct |
120 ms |
216336 KB |
Output is correct |
5 |
Correct |
120 ms |
216276 KB |
Output is correct |
6 |
Correct |
125 ms |
216268 KB |
Output is correct |
7 |
Correct |
120 ms |
216332 KB |
Output is correct |
8 |
Correct |
120 ms |
216428 KB |
Output is correct |
9 |
Correct |
120 ms |
216252 KB |
Output is correct |
10 |
Correct |
121 ms |
216360 KB |
Output is correct |
11 |
Correct |
121 ms |
216372 KB |
Output is correct |
12 |
Correct |
118 ms |
216316 KB |
Output is correct |
13 |
Correct |
119 ms |
216388 KB |
Output is correct |
14 |
Correct |
121 ms |
216448 KB |
Output is correct |
15 |
Correct |
118 ms |
216312 KB |
Output is correct |
16 |
Correct |
119 ms |
216516 KB |
Output is correct |
17 |
Correct |
121 ms |
216448 KB |
Output is correct |
18 |
Correct |
119 ms |
216388 KB |
Output is correct |
19 |
Correct |
120 ms |
216472 KB |
Output is correct |
20 |
Correct |
124 ms |
216420 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
127 ms |
216388 KB |
Output is correct |
2 |
Correct |
119 ms |
216300 KB |
Output is correct |
3 |
Correct |
118 ms |
216368 KB |
Output is correct |
4 |
Correct |
118 ms |
216356 KB |
Output is correct |
5 |
Correct |
118 ms |
216292 KB |
Output is correct |
6 |
Correct |
120 ms |
216440 KB |
Output is correct |
7 |
Correct |
116 ms |
216316 KB |
Output is correct |
8 |
Correct |
118 ms |
216240 KB |
Output is correct |
9 |
Correct |
118 ms |
216340 KB |
Output is correct |
10 |
Correct |
118 ms |
216332 KB |
Output is correct |
11 |
Correct |
119 ms |
216384 KB |
Output is correct |
12 |
Correct |
118 ms |
216304 KB |
Output is correct |
13 |
Correct |
119 ms |
216388 KB |
Output is correct |
14 |
Correct |
120 ms |
216452 KB |
Output is correct |
15 |
Correct |
119 ms |
216352 KB |
Output is correct |
16 |
Correct |
121 ms |
216276 KB |
Output is correct |
17 |
Correct |
120 ms |
216232 KB |
Output is correct |
18 |
Correct |
120 ms |
216296 KB |
Output is correct |
19 |
Correct |
120 ms |
216356 KB |
Output is correct |
20 |
Correct |
120 ms |
216340 KB |
Output is correct |
21 |
Correct |
118 ms |
216236 KB |
Output is correct |
22 |
Correct |
120 ms |
216336 KB |
Output is correct |
23 |
Correct |
120 ms |
216276 KB |
Output is correct |
24 |
Correct |
125 ms |
216268 KB |
Output is correct |
25 |
Correct |
120 ms |
216332 KB |
Output is correct |
26 |
Correct |
120 ms |
216428 KB |
Output is correct |
27 |
Correct |
120 ms |
216252 KB |
Output is correct |
28 |
Correct |
121 ms |
216360 KB |
Output is correct |
29 |
Correct |
121 ms |
216372 KB |
Output is correct |
30 |
Correct |
118 ms |
216316 KB |
Output is correct |
31 |
Correct |
119 ms |
216388 KB |
Output is correct |
32 |
Correct |
121 ms |
216448 KB |
Output is correct |
33 |
Correct |
118 ms |
216312 KB |
Output is correct |
34 |
Correct |
119 ms |
216516 KB |
Output is correct |
35 |
Correct |
121 ms |
216448 KB |
Output is correct |
36 |
Correct |
119 ms |
216388 KB |
Output is correct |
37 |
Correct |
120 ms |
216472 KB |
Output is correct |
38 |
Correct |
124 ms |
216420 KB |
Output is correct |
39 |
Correct |
125 ms |
217316 KB |
Output is correct |
40 |
Correct |
121 ms |
216456 KB |
Output is correct |
41 |
Correct |
119 ms |
216304 KB |
Output is correct |
42 |
Correct |
120 ms |
216260 KB |
Output is correct |
43 |
Correct |
122 ms |
216304 KB |
Output is correct |
44 |
Correct |
119 ms |
216324 KB |
Output is correct |
45 |
Correct |
122 ms |
216260 KB |
Output is correct |
46 |
Correct |
121 ms |
216248 KB |
Output is correct |
47 |
Correct |
119 ms |
216308 KB |
Output is correct |
48 |
Correct |
120 ms |
216356 KB |
Output is correct |
49 |
Correct |
120 ms |
216376 KB |
Output is correct |
50 |
Correct |
120 ms |
216412 KB |
Output is correct |
51 |
Correct |
123 ms |
216900 KB |
Output is correct |
52 |
Correct |
121 ms |
216764 KB |
Output is correct |
53 |
Correct |
125 ms |
217968 KB |
Output is correct |
54 |
Correct |
124 ms |
217924 KB |
Output is correct |
55 |
Correct |
125 ms |
217176 KB |
Output is correct |
56 |
Correct |
124 ms |
218508 KB |
Output is correct |
57 |
Correct |
125 ms |
216936 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
127 ms |
216388 KB |
Output is correct |
2 |
Correct |
119 ms |
216300 KB |
Output is correct |
3 |
Correct |
118 ms |
216368 KB |
Output is correct |
4 |
Correct |
118 ms |
216356 KB |
Output is correct |
5 |
Correct |
118 ms |
216292 KB |
Output is correct |
6 |
Correct |
120 ms |
216440 KB |
Output is correct |
7 |
Correct |
116 ms |
216316 KB |
Output is correct |
8 |
Correct |
118 ms |
216240 KB |
Output is correct |
9 |
Correct |
118 ms |
216340 KB |
Output is correct |
10 |
Correct |
118 ms |
216332 KB |
Output is correct |
11 |
Correct |
119 ms |
216384 KB |
Output is correct |
12 |
Correct |
118 ms |
216304 KB |
Output is correct |
13 |
Correct |
119 ms |
216388 KB |
Output is correct |
14 |
Correct |
120 ms |
216452 KB |
Output is correct |
15 |
Correct |
119 ms |
216352 KB |
Output is correct |
16 |
Correct |
121 ms |
216276 KB |
Output is correct |
17 |
Correct |
120 ms |
216232 KB |
Output is correct |
18 |
Correct |
120 ms |
216296 KB |
Output is correct |
19 |
Correct |
120 ms |
216356 KB |
Output is correct |
20 |
Correct |
120 ms |
216340 KB |
Output is correct |
21 |
Correct |
118 ms |
216236 KB |
Output is correct |
22 |
Correct |
120 ms |
216336 KB |
Output is correct |
23 |
Correct |
120 ms |
216276 KB |
Output is correct |
24 |
Correct |
125 ms |
216268 KB |
Output is correct |
25 |
Correct |
120 ms |
216332 KB |
Output is correct |
26 |
Correct |
120 ms |
216428 KB |
Output is correct |
27 |
Correct |
120 ms |
216252 KB |
Output is correct |
28 |
Correct |
121 ms |
216360 KB |
Output is correct |
29 |
Correct |
121 ms |
216372 KB |
Output is correct |
30 |
Correct |
118 ms |
216316 KB |
Output is correct |
31 |
Correct |
119 ms |
216388 KB |
Output is correct |
32 |
Correct |
121 ms |
216448 KB |
Output is correct |
33 |
Correct |
118 ms |
216312 KB |
Output is correct |
34 |
Correct |
119 ms |
216516 KB |
Output is correct |
35 |
Correct |
121 ms |
216448 KB |
Output is correct |
36 |
Correct |
119 ms |
216388 KB |
Output is correct |
37 |
Correct |
120 ms |
216472 KB |
Output is correct |
38 |
Correct |
124 ms |
216420 KB |
Output is correct |
39 |
Correct |
125 ms |
217316 KB |
Output is correct |
40 |
Correct |
121 ms |
216456 KB |
Output is correct |
41 |
Correct |
119 ms |
216304 KB |
Output is correct |
42 |
Correct |
120 ms |
216260 KB |
Output is correct |
43 |
Correct |
122 ms |
216304 KB |
Output is correct |
44 |
Correct |
119 ms |
216324 KB |
Output is correct |
45 |
Correct |
122 ms |
216260 KB |
Output is correct |
46 |
Correct |
121 ms |
216248 KB |
Output is correct |
47 |
Correct |
119 ms |
216308 KB |
Output is correct |
48 |
Correct |
120 ms |
216356 KB |
Output is correct |
49 |
Correct |
120 ms |
216376 KB |
Output is correct |
50 |
Correct |
120 ms |
216412 KB |
Output is correct |
51 |
Correct |
123 ms |
216900 KB |
Output is correct |
52 |
Correct |
121 ms |
216764 KB |
Output is correct |
53 |
Correct |
125 ms |
217968 KB |
Output is correct |
54 |
Correct |
124 ms |
217924 KB |
Output is correct |
55 |
Correct |
125 ms |
217176 KB |
Output is correct |
56 |
Correct |
124 ms |
218508 KB |
Output is correct |
57 |
Correct |
125 ms |
216936 KB |
Output is correct |
58 |
Correct |
256 ms |
218940 KB |
Output is correct |
59 |
Correct |
131 ms |
216260 KB |
Output is correct |
60 |
Correct |
270 ms |
218480 KB |
Output is correct |
61 |
Execution timed out |
1105 ms |
229884 KB |
Time limit exceeded |
62 |
Halted |
0 ms |
0 KB |
- |