#include "jumps.h"
#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> v,a,b,pl,mark;
int jump[20][200005];
int jump1[20][200005];
void init(int N, vector<int> H) {
n=N;
v=H;
a.resize(n,-1);
b.resize(n,-1);
pl.resize(n+1);
mark.resize(n+1);
vector<int> st;
for(int i=0;i<n;i++){
pl[v[i]]=i;
while(st.size()&&v[st.back()]<v[i]){
st.pop_back();
}
a[i]=(st.size()?st.back():-1);
st.push_back(i);
}
st.clear();
for(int i=n-1;i>=0;i--){
while(st.size()&&v[st.back()]<v[i]){
st.pop_back();
}
b[i]=(st.size()?st.back():-1);
st.push_back(i);
}
for(int i=0;i<n;i++){
if(a[i]==-1){
swap(a[i],b[i]);
mark[i]=1;
}
else if(b[i]==-1){
continue;
}
else {
if(v[a[i]]<v[b[i]]){
swap(a[i],b[i]);
mark[i]=1;
}
}
}
for(int j=n;j>=1;j--){
int i=pl[j];
int now=a[i];
jump[0][i]=now;
for(int k=1;k<20;k++){
if(now==-1){
jump[k][i]=-1;
continue;
}
else{
now=jump[k][i]=jump[k-1][now];
}
}
now=b[i];
jump1[0][i]=now;
for(int k=1;k<20;k++){
if(now==-1){
jump1[k][i]=-1;
continue;
}
else{
now=jump1[k][i]=jump1[k-1][now];
}
}
}
for(int i=0;i<n;i++){
if(mark[i]){
swap(a[i],b[i]);
}
}
}
int f(int A, int C) {
int ans=0;
int now=A;
for(int k=19;k>=0;k--){
int tmp=jump[k][now];
if(tmp!=-1&&v[tmp]<=v[C]){
ans+=(1<<k);
now=tmp;
}
}
for(int k=19;k>=0;k--){
int tmp=jump1[k][now];
if(tmp!=-1&&v[tmp]<=v[C]){
ans+=(1<<k);
now=tmp;
}
}
if(now!=C)ans=1e9;
return ans;
}
int minimum_jumps(int A, int B, int C, int D) {
int ans=1e9;
for(int i=A;i<=B;i++){
if(b[i]!=-1&&b[i]<=B)continue;
for(int j=C;j<=D;j++){
if(a[j]!=-1&&a[j]>=C)continue;
ans=min(ans,f(i,j));
}
}
if(ans==1e9)ans=-1;
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
31064 KB |
Output is correct |
2 |
Correct |
3 ms |
31064 KB |
Output is correct |
3 |
Execution timed out |
4022 ms |
36512 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
31064 KB |
Output is correct |
2 |
Correct |
3 ms |
31064 KB |
Output is correct |
3 |
Correct |
4 ms |
31064 KB |
Output is correct |
4 |
Correct |
4 ms |
31064 KB |
Output is correct |
5 |
Correct |
4 ms |
31064 KB |
Output is correct |
6 |
Correct |
4 ms |
31064 KB |
Output is correct |
7 |
Correct |
5 ms |
31064 KB |
Output is correct |
8 |
Correct |
5 ms |
31064 KB |
Output is correct |
9 |
Correct |
4 ms |
31064 KB |
Output is correct |
10 |
Correct |
5 ms |
31064 KB |
Output is correct |
11 |
Correct |
5 ms |
31064 KB |
Output is correct |
12 |
Correct |
5 ms |
31064 KB |
Output is correct |
13 |
Correct |
5 ms |
31064 KB |
Output is correct |
14 |
Correct |
4 ms |
31064 KB |
Output is correct |
15 |
Correct |
11 ms |
31064 KB |
Output is correct |
16 |
Correct |
11 ms |
31064 KB |
Output is correct |
17 |
Correct |
6 ms |
31064 KB |
Output is correct |
18 |
Correct |
4 ms |
31064 KB |
Output is correct |
19 |
Correct |
4 ms |
31156 KB |
Output is correct |
20 |
Correct |
5 ms |
31064 KB |
Output is correct |
21 |
Correct |
4 ms |
31064 KB |
Output is correct |
22 |
Correct |
5 ms |
31064 KB |
Output is correct |
23 |
Correct |
5 ms |
31064 KB |
Output is correct |
24 |
Correct |
5 ms |
31064 KB |
Output is correct |
25 |
Correct |
4 ms |
31168 KB |
Output is correct |
26 |
Correct |
3 ms |
31064 KB |
Output is correct |
27 |
Correct |
4 ms |
31064 KB |
Output is correct |
28 |
Correct |
4 ms |
31064 KB |
Output is correct |
29 |
Correct |
4 ms |
31064 KB |
Output is correct |
30 |
Correct |
5 ms |
31064 KB |
Output is correct |
31 |
Correct |
5 ms |
31064 KB |
Output is correct |
32 |
Correct |
4 ms |
31064 KB |
Output is correct |
33 |
Correct |
4 ms |
31064 KB |
Output is correct |
34 |
Correct |
4 ms |
31064 KB |
Output is correct |
35 |
Correct |
4 ms |
31064 KB |
Output is correct |
36 |
Correct |
4 ms |
31064 KB |
Output is correct |
37 |
Correct |
4 ms |
31064 KB |
Output is correct |
38 |
Correct |
4 ms |
31220 KB |
Output is correct |
39 |
Correct |
4 ms |
31064 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
31064 KB |
Output is correct |
2 |
Correct |
3 ms |
31064 KB |
Output is correct |
3 |
Correct |
4 ms |
31064 KB |
Output is correct |
4 |
Correct |
4 ms |
31064 KB |
Output is correct |
5 |
Correct |
4 ms |
31064 KB |
Output is correct |
6 |
Correct |
4 ms |
31064 KB |
Output is correct |
7 |
Correct |
5 ms |
31064 KB |
Output is correct |
8 |
Correct |
5 ms |
31064 KB |
Output is correct |
9 |
Correct |
4 ms |
31064 KB |
Output is correct |
10 |
Correct |
5 ms |
31064 KB |
Output is correct |
11 |
Correct |
5 ms |
31064 KB |
Output is correct |
12 |
Correct |
5 ms |
31064 KB |
Output is correct |
13 |
Correct |
5 ms |
31064 KB |
Output is correct |
14 |
Correct |
4 ms |
31064 KB |
Output is correct |
15 |
Correct |
11 ms |
31064 KB |
Output is correct |
16 |
Correct |
11 ms |
31064 KB |
Output is correct |
17 |
Correct |
6 ms |
31064 KB |
Output is correct |
18 |
Correct |
4 ms |
31064 KB |
Output is correct |
19 |
Correct |
4 ms |
31156 KB |
Output is correct |
20 |
Correct |
5 ms |
31064 KB |
Output is correct |
21 |
Correct |
4 ms |
31064 KB |
Output is correct |
22 |
Correct |
5 ms |
31064 KB |
Output is correct |
23 |
Correct |
5 ms |
31064 KB |
Output is correct |
24 |
Correct |
5 ms |
31064 KB |
Output is correct |
25 |
Correct |
4 ms |
31168 KB |
Output is correct |
26 |
Correct |
3 ms |
31064 KB |
Output is correct |
27 |
Correct |
4 ms |
31064 KB |
Output is correct |
28 |
Correct |
4 ms |
31064 KB |
Output is correct |
29 |
Correct |
4 ms |
31064 KB |
Output is correct |
30 |
Correct |
5 ms |
31064 KB |
Output is correct |
31 |
Correct |
5 ms |
31064 KB |
Output is correct |
32 |
Correct |
4 ms |
31064 KB |
Output is correct |
33 |
Correct |
4 ms |
31064 KB |
Output is correct |
34 |
Correct |
4 ms |
31064 KB |
Output is correct |
35 |
Correct |
4 ms |
31064 KB |
Output is correct |
36 |
Correct |
4 ms |
31064 KB |
Output is correct |
37 |
Correct |
4 ms |
31064 KB |
Output is correct |
38 |
Correct |
4 ms |
31220 KB |
Output is correct |
39 |
Correct |
4 ms |
31064 KB |
Output is correct |
40 |
Correct |
4 ms |
31064 KB |
Output is correct |
41 |
Correct |
4 ms |
31204 KB |
Output is correct |
42 |
Correct |
4 ms |
31064 KB |
Output is correct |
43 |
Correct |
4 ms |
31064 KB |
Output is correct |
44 |
Correct |
4 ms |
31064 KB |
Output is correct |
45 |
Correct |
4 ms |
31064 KB |
Output is correct |
46 |
Correct |
4 ms |
31064 KB |
Output is correct |
47 |
Correct |
4 ms |
31064 KB |
Output is correct |
48 |
Correct |
4 ms |
31064 KB |
Output is correct |
49 |
Correct |
4 ms |
31064 KB |
Output is correct |
50 |
Correct |
4 ms |
31064 KB |
Output is correct |
51 |
Correct |
5 ms |
31064 KB |
Output is correct |
52 |
Correct |
5 ms |
31064 KB |
Output is correct |
53 |
Correct |
4 ms |
31064 KB |
Output is correct |
54 |
Correct |
10 ms |
31064 KB |
Output is correct |
55 |
Correct |
11 ms |
31064 KB |
Output is correct |
56 |
Correct |
6 ms |
31064 KB |
Output is correct |
57 |
Correct |
4 ms |
31180 KB |
Output is correct |
58 |
Correct |
17 ms |
31060 KB |
Output is correct |
59 |
Correct |
20 ms |
31064 KB |
Output is correct |
60 |
Correct |
7 ms |
31064 KB |
Output is correct |
61 |
Correct |
21 ms |
31064 KB |
Output is correct |
62 |
Correct |
11 ms |
31064 KB |
Output is correct |
63 |
Correct |
20 ms |
31064 KB |
Output is correct |
64 |
Correct |
47 ms |
31064 KB |
Output is correct |
65 |
Correct |
50 ms |
31064 KB |
Output is correct |
66 |
Correct |
52 ms |
31064 KB |
Output is correct |
67 |
Correct |
19 ms |
31064 KB |
Output is correct |
68 |
Execution timed out |
4059 ms |
31064 KB |
Time limit exceeded |
69 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
31064 KB |
Output is correct |
2 |
Correct |
4 ms |
31064 KB |
Output is correct |
3 |
Correct |
4 ms |
31200 KB |
Output is correct |
4 |
Correct |
4 ms |
31064 KB |
Output is correct |
5 |
Correct |
65 ms |
35876 KB |
Output is correct |
6 |
Correct |
84 ms |
37224 KB |
Output is correct |
7 |
Correct |
33 ms |
33976 KB |
Output is correct |
8 |
Correct |
91 ms |
37248 KB |
Output is correct |
9 |
Correct |
10 ms |
32088 KB |
Output is correct |
10 |
Correct |
91 ms |
37232 KB |
Output is correct |
11 |
Correct |
48 ms |
37932 KB |
Output is correct |
12 |
Correct |
69 ms |
37836 KB |
Output is correct |
13 |
Correct |
43 ms |
37804 KB |
Output is correct |
14 |
Correct |
80 ms |
37228 KB |
Output is correct |
15 |
Execution timed out |
4054 ms |
37664 KB |
Time limit exceeded |
16 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
31064 KB |
Output is correct |
2 |
Correct |
3 ms |
31064 KB |
Output is correct |
3 |
Correct |
4 ms |
31064 KB |
Output is correct |
4 |
Correct |
167 ms |
33908 KB |
Output is correct |
5 |
Correct |
740 ms |
37072 KB |
Output is correct |
6 |
Correct |
429 ms |
32084 KB |
Output is correct |
7 |
Correct |
717 ms |
37068 KB |
Output is correct |
8 |
Correct |
366 ms |
33112 KB |
Output is correct |
9 |
Correct |
707 ms |
37320 KB |
Output is correct |
10 |
Correct |
729 ms |
37956 KB |
Output is correct |
11 |
Correct |
669 ms |
37932 KB |
Output is correct |
12 |
Correct |
730 ms |
37948 KB |
Output is correct |
13 |
Correct |
711 ms |
37076 KB |
Output is correct |
14 |
Correct |
695 ms |
37684 KB |
Output is correct |
15 |
Correct |
600 ms |
37952 KB |
Output is correct |
16 |
Correct |
652 ms |
37936 KB |
Output is correct |
17 |
Correct |
4 ms |
31064 KB |
Output is correct |
18 |
Correct |
3 ms |
31064 KB |
Output is correct |
19 |
Correct |
4 ms |
31064 KB |
Output is correct |
20 |
Correct |
4 ms |
31064 KB |
Output is correct |
21 |
Correct |
4 ms |
31064 KB |
Output is correct |
22 |
Correct |
4 ms |
31064 KB |
Output is correct |
23 |
Correct |
4 ms |
31064 KB |
Output is correct |
24 |
Correct |
4 ms |
31064 KB |
Output is correct |
25 |
Correct |
4 ms |
31064 KB |
Output is correct |
26 |
Correct |
4 ms |
31064 KB |
Output is correct |
27 |
Correct |
14 ms |
31064 KB |
Output is correct |
28 |
Correct |
13 ms |
31276 KB |
Output is correct |
29 |
Correct |
14 ms |
31064 KB |
Output is correct |
30 |
Correct |
11 ms |
31248 KB |
Output is correct |
31 |
Correct |
11 ms |
31064 KB |
Output is correct |
32 |
Correct |
4 ms |
31064 KB |
Output is correct |
33 |
Correct |
43 ms |
34616 KB |
Output is correct |
34 |
Correct |
95 ms |
37048 KB |
Output is correct |
35 |
Correct |
40 ms |
37952 KB |
Output is correct |
36 |
Correct |
73 ms |
37236 KB |
Output is correct |
37 |
Correct |
44 ms |
37696 KB |
Output is correct |
38 |
Correct |
45 ms |
37916 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
31064 KB |
Output is correct |
2 |
Correct |
3 ms |
31064 KB |
Output is correct |
3 |
Correct |
4 ms |
31064 KB |
Output is correct |
4 |
Correct |
167 ms |
33908 KB |
Output is correct |
5 |
Correct |
740 ms |
37072 KB |
Output is correct |
6 |
Correct |
429 ms |
32084 KB |
Output is correct |
7 |
Correct |
717 ms |
37068 KB |
Output is correct |
8 |
Correct |
366 ms |
33112 KB |
Output is correct |
9 |
Correct |
707 ms |
37320 KB |
Output is correct |
10 |
Correct |
729 ms |
37956 KB |
Output is correct |
11 |
Correct |
669 ms |
37932 KB |
Output is correct |
12 |
Correct |
730 ms |
37948 KB |
Output is correct |
13 |
Correct |
711 ms |
37076 KB |
Output is correct |
14 |
Correct |
695 ms |
37684 KB |
Output is correct |
15 |
Correct |
600 ms |
37952 KB |
Output is correct |
16 |
Correct |
652 ms |
37936 KB |
Output is correct |
17 |
Correct |
4 ms |
31064 KB |
Output is correct |
18 |
Correct |
3 ms |
31064 KB |
Output is correct |
19 |
Correct |
4 ms |
31064 KB |
Output is correct |
20 |
Correct |
4 ms |
31064 KB |
Output is correct |
21 |
Correct |
4 ms |
31064 KB |
Output is correct |
22 |
Correct |
4 ms |
31064 KB |
Output is correct |
23 |
Correct |
4 ms |
31064 KB |
Output is correct |
24 |
Correct |
4 ms |
31064 KB |
Output is correct |
25 |
Correct |
4 ms |
31064 KB |
Output is correct |
26 |
Correct |
4 ms |
31064 KB |
Output is correct |
27 |
Correct |
14 ms |
31064 KB |
Output is correct |
28 |
Correct |
13 ms |
31276 KB |
Output is correct |
29 |
Correct |
14 ms |
31064 KB |
Output is correct |
30 |
Correct |
11 ms |
31248 KB |
Output is correct |
31 |
Correct |
11 ms |
31064 KB |
Output is correct |
32 |
Correct |
4 ms |
31064 KB |
Output is correct |
33 |
Correct |
43 ms |
34616 KB |
Output is correct |
34 |
Correct |
95 ms |
37048 KB |
Output is correct |
35 |
Correct |
40 ms |
37952 KB |
Output is correct |
36 |
Correct |
73 ms |
37236 KB |
Output is correct |
37 |
Correct |
44 ms |
37696 KB |
Output is correct |
38 |
Correct |
45 ms |
37916 KB |
Output is correct |
39 |
Correct |
3 ms |
31064 KB |
Output is correct |
40 |
Correct |
4 ms |
31064 KB |
Output is correct |
41 |
Correct |
4 ms |
31064 KB |
Output is correct |
42 |
Correct |
167 ms |
33920 KB |
Output is correct |
43 |
Correct |
761 ms |
37236 KB |
Output is correct |
44 |
Correct |
427 ms |
32088 KB |
Output is correct |
45 |
Correct |
710 ms |
37060 KB |
Output is correct |
46 |
Correct |
361 ms |
33304 KB |
Output is correct |
47 |
Correct |
679 ms |
37072 KB |
Output is correct |
48 |
Correct |
746 ms |
37936 KB |
Output is correct |
49 |
Correct |
719 ms |
37944 KB |
Output is correct |
50 |
Correct |
756 ms |
37952 KB |
Output is correct |
51 |
Correct |
691 ms |
37072 KB |
Output is correct |
52 |
Correct |
705 ms |
37692 KB |
Output is correct |
53 |
Correct |
674 ms |
37952 KB |
Output is correct |
54 |
Correct |
654 ms |
37932 KB |
Output is correct |
55 |
Correct |
4 ms |
31316 KB |
Output is correct |
56 |
Correct |
497 ms |
37204 KB |
Output is correct |
57 |
Execution timed out |
4049 ms |
37064 KB |
Time limit exceeded |
58 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
31064 KB |
Output is correct |
2 |
Correct |
3 ms |
31064 KB |
Output is correct |
3 |
Execution timed out |
4022 ms |
36512 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |