#include <iostream>
#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);
}
}
int query(int L, int D, int x, int l, int d){
propagate(x);
if(L>=l && D<=d){
return t[x];
}
int lijeva=1e9, desna=1e9;
if((L+D)/2>=l){
lijeva=query(L, (L+D)/2, x*2, l, d);
}
if((L+D)/2+1<=d){
desna=query((L+D)/2+1, D, x*2+1, l, d);
}
return min(lijeva, desna);
}
};
struct logaritamska{
int l[maxn];
void update(int x, int val){
for(; x<maxn; x+=(x & -x)){
l[x]=max(l[x], val);
}
}
int query(int x){
int sol=0;
for(; x>0; x-=(x & -x)){
sol=max(sol, l[x]);
}
return sol;
}
};
tournament T[maxk];
logaritamska L;
int n, k;
int rijesi(int x, int pos){
int rev=maxn-pos;
int lo=rev, hi=maxn-1, mid;
while(lo<hi){
mid=(lo+hi)/2+1;
if(L.query(mid)<x){
lo=mid;
}
else{
hi=mid-1;
}
}
L.update(rev, x);
return maxn-lo;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> k;
int a;
int pos;
int maksi=0;
for(int i=0; i<n; i++){
cin >> a;
maksi=max(maksi, a);
pos=rijesi(a, i+1)-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){
cout << maksi << '\n';
}
else{
cout << T[k].mindp[n+pot] << '\n';
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
125 ms |
216296 KB |
Output is correct |
2 |
Correct |
118 ms |
216392 KB |
Output is correct |
3 |
Correct |
118 ms |
216328 KB |
Output is correct |
4 |
Correct |
117 ms |
216388 KB |
Output is correct |
5 |
Correct |
126 ms |
216388 KB |
Output is correct |
6 |
Correct |
117 ms |
216388 KB |
Output is correct |
7 |
Correct |
119 ms |
216420 KB |
Output is correct |
8 |
Correct |
122 ms |
216388 KB |
Output is correct |
9 |
Correct |
119 ms |
216388 KB |
Output is correct |
10 |
Correct |
118 ms |
216388 KB |
Output is correct |
11 |
Correct |
118 ms |
216392 KB |
Output is correct |
12 |
Correct |
116 ms |
216380 KB |
Output is correct |
13 |
Correct |
119 ms |
216388 KB |
Output is correct |
14 |
Correct |
120 ms |
216392 KB |
Output is correct |
15 |
Correct |
119 ms |
216276 KB |
Output is correct |
16 |
Correct |
118 ms |
216404 KB |
Output is correct |
17 |
Correct |
125 ms |
216292 KB |
Output is correct |
18 |
Correct |
121 ms |
216376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
118 ms |
216388 KB |
Output is correct |
2 |
Correct |
120 ms |
216360 KB |
Output is correct |
3 |
Correct |
119 ms |
216468 KB |
Output is correct |
4 |
Correct |
118 ms |
216388 KB |
Output is correct |
5 |
Correct |
118 ms |
216400 KB |
Output is correct |
6 |
Correct |
118 ms |
216312 KB |
Output is correct |
7 |
Correct |
121 ms |
216288 KB |
Output is correct |
8 |
Correct |
121 ms |
216416 KB |
Output is correct |
9 |
Correct |
119 ms |
216360 KB |
Output is correct |
10 |
Correct |
119 ms |
216388 KB |
Output is correct |
11 |
Correct |
121 ms |
216388 KB |
Output is correct |
12 |
Correct |
124 ms |
216380 KB |
Output is correct |
13 |
Correct |
132 ms |
216384 KB |
Output is correct |
14 |
Correct |
117 ms |
216528 KB |
Output is correct |
15 |
Correct |
120 ms |
216396 KB |
Output is correct |
16 |
Correct |
120 ms |
216644 KB |
Output is correct |
17 |
Correct |
120 ms |
216392 KB |
Output is correct |
18 |
Correct |
118 ms |
216404 KB |
Output is correct |
19 |
Correct |
119 ms |
216412 KB |
Output is correct |
20 |
Correct |
119 ms |
216576 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
125 ms |
216296 KB |
Output is correct |
2 |
Correct |
118 ms |
216392 KB |
Output is correct |
3 |
Correct |
118 ms |
216328 KB |
Output is correct |
4 |
Correct |
117 ms |
216388 KB |
Output is correct |
5 |
Correct |
126 ms |
216388 KB |
Output is correct |
6 |
Correct |
117 ms |
216388 KB |
Output is correct |
7 |
Correct |
119 ms |
216420 KB |
Output is correct |
8 |
Correct |
122 ms |
216388 KB |
Output is correct |
9 |
Correct |
119 ms |
216388 KB |
Output is correct |
10 |
Correct |
118 ms |
216388 KB |
Output is correct |
11 |
Correct |
118 ms |
216392 KB |
Output is correct |
12 |
Correct |
116 ms |
216380 KB |
Output is correct |
13 |
Correct |
119 ms |
216388 KB |
Output is correct |
14 |
Correct |
120 ms |
216392 KB |
Output is correct |
15 |
Correct |
119 ms |
216276 KB |
Output is correct |
16 |
Correct |
118 ms |
216404 KB |
Output is correct |
17 |
Correct |
125 ms |
216292 KB |
Output is correct |
18 |
Correct |
121 ms |
216376 KB |
Output is correct |
19 |
Correct |
118 ms |
216388 KB |
Output is correct |
20 |
Correct |
120 ms |
216360 KB |
Output is correct |
21 |
Correct |
119 ms |
216468 KB |
Output is correct |
22 |
Correct |
118 ms |
216388 KB |
Output is correct |
23 |
Correct |
118 ms |
216400 KB |
Output is correct |
24 |
Correct |
118 ms |
216312 KB |
Output is correct |
25 |
Correct |
121 ms |
216288 KB |
Output is correct |
26 |
Correct |
121 ms |
216416 KB |
Output is correct |
27 |
Correct |
119 ms |
216360 KB |
Output is correct |
28 |
Correct |
119 ms |
216388 KB |
Output is correct |
29 |
Correct |
121 ms |
216388 KB |
Output is correct |
30 |
Correct |
124 ms |
216380 KB |
Output is correct |
31 |
Correct |
132 ms |
216384 KB |
Output is correct |
32 |
Correct |
117 ms |
216528 KB |
Output is correct |
33 |
Correct |
120 ms |
216396 KB |
Output is correct |
34 |
Correct |
120 ms |
216644 KB |
Output is correct |
35 |
Correct |
120 ms |
216392 KB |
Output is correct |
36 |
Correct |
118 ms |
216404 KB |
Output is correct |
37 |
Correct |
119 ms |
216412 KB |
Output is correct |
38 |
Correct |
119 ms |
216576 KB |
Output is correct |
39 |
Correct |
142 ms |
217288 KB |
Output is correct |
40 |
Correct |
134 ms |
216376 KB |
Output is correct |
41 |
Correct |
121 ms |
216280 KB |
Output is correct |
42 |
Correct |
121 ms |
216376 KB |
Output is correct |
43 |
Correct |
120 ms |
216376 KB |
Output is correct |
44 |
Correct |
124 ms |
216328 KB |
Output is correct |
45 |
Correct |
120 ms |
216312 KB |
Output is correct |
46 |
Correct |
120 ms |
216380 KB |
Output is correct |
47 |
Correct |
127 ms |
216292 KB |
Output is correct |
48 |
Correct |
119 ms |
216480 KB |
Output is correct |
49 |
Correct |
134 ms |
216316 KB |
Output is correct |
50 |
Correct |
122 ms |
216420 KB |
Output is correct |
51 |
Correct |
125 ms |
216896 KB |
Output is correct |
52 |
Correct |
127 ms |
216772 KB |
Output is correct |
53 |
Correct |
128 ms |
218012 KB |
Output is correct |
54 |
Correct |
136 ms |
217820 KB |
Output is correct |
55 |
Correct |
127 ms |
217152 KB |
Output is correct |
56 |
Correct |
136 ms |
218552 KB |
Output is correct |
57 |
Correct |
133 ms |
217004 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
125 ms |
216296 KB |
Output is correct |
2 |
Correct |
118 ms |
216392 KB |
Output is correct |
3 |
Correct |
118 ms |
216328 KB |
Output is correct |
4 |
Correct |
117 ms |
216388 KB |
Output is correct |
5 |
Correct |
126 ms |
216388 KB |
Output is correct |
6 |
Correct |
117 ms |
216388 KB |
Output is correct |
7 |
Correct |
119 ms |
216420 KB |
Output is correct |
8 |
Correct |
122 ms |
216388 KB |
Output is correct |
9 |
Correct |
119 ms |
216388 KB |
Output is correct |
10 |
Correct |
118 ms |
216388 KB |
Output is correct |
11 |
Correct |
118 ms |
216392 KB |
Output is correct |
12 |
Correct |
116 ms |
216380 KB |
Output is correct |
13 |
Correct |
119 ms |
216388 KB |
Output is correct |
14 |
Correct |
120 ms |
216392 KB |
Output is correct |
15 |
Correct |
119 ms |
216276 KB |
Output is correct |
16 |
Correct |
118 ms |
216404 KB |
Output is correct |
17 |
Correct |
125 ms |
216292 KB |
Output is correct |
18 |
Correct |
121 ms |
216376 KB |
Output is correct |
19 |
Correct |
118 ms |
216388 KB |
Output is correct |
20 |
Correct |
120 ms |
216360 KB |
Output is correct |
21 |
Correct |
119 ms |
216468 KB |
Output is correct |
22 |
Correct |
118 ms |
216388 KB |
Output is correct |
23 |
Correct |
118 ms |
216400 KB |
Output is correct |
24 |
Correct |
118 ms |
216312 KB |
Output is correct |
25 |
Correct |
121 ms |
216288 KB |
Output is correct |
26 |
Correct |
121 ms |
216416 KB |
Output is correct |
27 |
Correct |
119 ms |
216360 KB |
Output is correct |
28 |
Correct |
119 ms |
216388 KB |
Output is correct |
29 |
Correct |
121 ms |
216388 KB |
Output is correct |
30 |
Correct |
124 ms |
216380 KB |
Output is correct |
31 |
Correct |
132 ms |
216384 KB |
Output is correct |
32 |
Correct |
117 ms |
216528 KB |
Output is correct |
33 |
Correct |
120 ms |
216396 KB |
Output is correct |
34 |
Correct |
120 ms |
216644 KB |
Output is correct |
35 |
Correct |
120 ms |
216392 KB |
Output is correct |
36 |
Correct |
118 ms |
216404 KB |
Output is correct |
37 |
Correct |
119 ms |
216412 KB |
Output is correct |
38 |
Correct |
119 ms |
216576 KB |
Output is correct |
39 |
Correct |
142 ms |
217288 KB |
Output is correct |
40 |
Correct |
134 ms |
216376 KB |
Output is correct |
41 |
Correct |
121 ms |
216280 KB |
Output is correct |
42 |
Correct |
121 ms |
216376 KB |
Output is correct |
43 |
Correct |
120 ms |
216376 KB |
Output is correct |
44 |
Correct |
124 ms |
216328 KB |
Output is correct |
45 |
Correct |
120 ms |
216312 KB |
Output is correct |
46 |
Correct |
120 ms |
216380 KB |
Output is correct |
47 |
Correct |
127 ms |
216292 KB |
Output is correct |
48 |
Correct |
119 ms |
216480 KB |
Output is correct |
49 |
Correct |
134 ms |
216316 KB |
Output is correct |
50 |
Correct |
122 ms |
216420 KB |
Output is correct |
51 |
Correct |
125 ms |
216896 KB |
Output is correct |
52 |
Correct |
127 ms |
216772 KB |
Output is correct |
53 |
Correct |
128 ms |
218012 KB |
Output is correct |
54 |
Correct |
136 ms |
217820 KB |
Output is correct |
55 |
Correct |
127 ms |
217152 KB |
Output is correct |
56 |
Correct |
136 ms |
218552 KB |
Output is correct |
57 |
Correct |
133 ms |
217004 KB |
Output is correct |
58 |
Correct |
291 ms |
218736 KB |
Output is correct |
59 |
Correct |
150 ms |
216764 KB |
Output is correct |
60 |
Correct |
295 ms |
218996 KB |
Output is correct |
61 |
Execution timed out |
1093 ms |
229372 KB |
Time limit exceeded |
62 |
Halted |
0 ms |
0 KB |
- |