#include "jumps.h"
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
const int maxn = (int)2e5+10;
const int maxlg = 24;
const int INF = (int)1e9;
int n, pr[maxn], nx[maxn];
int gis[maxlg][maxn], high[maxlg][maxn], movR[maxlg][maxn];
void calc(int jmp[][maxn]){
for(int i = 1; i < maxlg; i++)
for(int j = 0; j < n; j++)
if(jmp[i-1][j]!=-1) jmp[i][j] = jmp[i-1][jmp[i-1][j]];
}
void init(int N, vector<int> a) {
n = N;
stack<pair<int,int>> S;
memset(pr,-1,sizeof(pr));
memset(nx,-1,sizeof(nx));
memset(gis,-1,sizeof(gis));
memset(high,-1,sizeof(high));
memset(movR,-1,sizeof(movR));
for(int i = 0; i < n; i++){
while(!S.empty() and S.top().fi<a[i]) S.pop();
if(!S.empty()) pr[i] = S.top().se;
S.push({a[i],i});
}
while(!S.empty()) S.pop();
for(int i = n-1; i>=0; i--){
while(!S.empty() and S.top().fi<a[i]) S.pop();
if(!S.empty()) nx[i] = S.top().se;
S.push({a[i],i});
}
while(!S.empty()) S.pop();
for(int i = 0; i < n; i++){
if(pr[i]!=-1) gis[0][i]=pr[i];
if(nx[i]!=-1) movR[0][i]=nx[i];
if(pr[i]!=-1 and nx[i]!=-1)
high[0][i] = (a[pr[i]]<a[nx[i]]?nx[i]:pr[i]);
}
calc(gis), calc(high), calc(movR);
}
int get_path(int *x, int y, int z, int jmp[][maxn], int rx=0, int ry=maxn){
int tot = 0; ry = min(ry,y);
for(int i = 20; i >= 0; i--)
if(jmp[i][*x]>=rx and jmp[i][*x]<ry)
if(nx[jmp[i][*x]]!=-1 and nx[jmp[i][*x]]<=z)
*x = jmp[i][*x], tot+=(1<<i);
return tot;
}
int minimum_jumps(int A, int x, int C, int D) {
get_path(&x,C,D,gis,A);
int num1 = get_path(&x,C,D,high);
int num2 = get_path(&x,C,D,movR);
return ((nx[x]>=C and nx[x]<=D)?num1+num2+1:-1);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
23 ms |
58192 KB |
Output is correct |
2 |
Correct |
22 ms |
58192 KB |
Output is correct |
3 |
Correct |
132 ms |
60692 KB |
Output is correct |
4 |
Correct |
1185 ms |
61344 KB |
Output is correct |
5 |
Correct |
922 ms |
59764 KB |
Output is correct |
6 |
Correct |
1039 ms |
61348 KB |
Output is correct |
7 |
Correct |
661 ms |
60352 KB |
Output is correct |
8 |
Correct |
1024 ms |
61384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
23 ms |
58184 KB |
Output is correct |
2 |
Correct |
21 ms |
58088 KB |
Output is correct |
3 |
Correct |
21 ms |
58192 KB |
Output is correct |
4 |
Correct |
21 ms |
58136 KB |
Output is correct |
5 |
Correct |
22 ms |
58124 KB |
Output is correct |
6 |
Incorrect |
24 ms |
58208 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
23 ms |
58184 KB |
Output is correct |
2 |
Correct |
21 ms |
58088 KB |
Output is correct |
3 |
Correct |
21 ms |
58192 KB |
Output is correct |
4 |
Correct |
21 ms |
58136 KB |
Output is correct |
5 |
Correct |
22 ms |
58124 KB |
Output is correct |
6 |
Incorrect |
24 ms |
58208 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
58192 KB |
Output is correct |
2 |
Correct |
21 ms |
58120 KB |
Output is correct |
3 |
Correct |
23 ms |
58160 KB |
Output is correct |
4 |
Correct |
21 ms |
58192 KB |
Output is correct |
5 |
Correct |
50 ms |
59424 KB |
Output is correct |
6 |
Correct |
75 ms |
59720 KB |
Output is correct |
7 |
Correct |
46 ms |
59020 KB |
Output is correct |
8 |
Correct |
58 ms |
59720 KB |
Output is correct |
9 |
Correct |
27 ms |
58440 KB |
Output is correct |
10 |
Correct |
58 ms |
59700 KB |
Output is correct |
11 |
Correct |
63 ms |
61480 KB |
Output is correct |
12 |
Correct |
73 ms |
60952 KB |
Output is correct |
13 |
Correct |
54 ms |
60936 KB |
Output is correct |
14 |
Correct |
55 ms |
59720 KB |
Output is correct |
15 |
Incorrect |
53 ms |
60564 KB |
Output isn't correct |
16 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
24 ms |
58192 KB |
Output is correct |
2 |
Correct |
23 ms |
58192 KB |
Output is correct |
3 |
Correct |
22 ms |
58196 KB |
Output is correct |
4 |
Correct |
265 ms |
58860 KB |
Output is correct |
5 |
Correct |
1073 ms |
59780 KB |
Output is correct |
6 |
Correct |
735 ms |
58448 KB |
Output is correct |
7 |
Correct |
1020 ms |
59684 KB |
Output is correct |
8 |
Correct |
662 ms |
58696 KB |
Output is correct |
9 |
Correct |
800 ms |
59704 KB |
Output is correct |
10 |
Correct |
1051 ms |
61384 KB |
Output is correct |
11 |
Correct |
875 ms |
61236 KB |
Output is correct |
12 |
Correct |
1113 ms |
61184 KB |
Output is correct |
13 |
Correct |
757 ms |
59672 KB |
Output is correct |
14 |
Correct |
813 ms |
60604 KB |
Output is correct |
15 |
Correct |
1016 ms |
61368 KB |
Output is correct |
16 |
Correct |
691 ms |
61380 KB |
Output is correct |
17 |
Correct |
22 ms |
58192 KB |
Output is correct |
18 |
Correct |
25 ms |
58164 KB |
Output is correct |
19 |
Correct |
23 ms |
58192 KB |
Output is correct |
20 |
Correct |
24 ms |
58176 KB |
Output is correct |
21 |
Correct |
24 ms |
58212 KB |
Output is correct |
22 |
Correct |
24 ms |
58192 KB |
Output is correct |
23 |
Correct |
24 ms |
58116 KB |
Output is correct |
24 |
Correct |
24 ms |
58124 KB |
Output is correct |
25 |
Correct |
25 ms |
58192 KB |
Output is correct |
26 |
Correct |
27 ms |
58192 KB |
Output is correct |
27 |
Correct |
46 ms |
58108 KB |
Output is correct |
28 |
Correct |
45 ms |
58288 KB |
Output is correct |
29 |
Correct |
42 ms |
58192 KB |
Output is correct |
30 |
Correct |
40 ms |
58144 KB |
Output is correct |
31 |
Correct |
32 ms |
58216 KB |
Output is correct |
32 |
Correct |
23 ms |
58180 KB |
Output is correct |
33 |
Correct |
43 ms |
59132 KB |
Output is correct |
34 |
Correct |
63 ms |
59720 KB |
Output is correct |
35 |
Correct |
70 ms |
61096 KB |
Output is correct |
36 |
Correct |
57 ms |
59696 KB |
Output is correct |
37 |
Correct |
56 ms |
60572 KB |
Output is correct |
38 |
Correct |
57 ms |
61372 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
24 ms |
58192 KB |
Output is correct |
2 |
Correct |
23 ms |
58192 KB |
Output is correct |
3 |
Correct |
22 ms |
58196 KB |
Output is correct |
4 |
Correct |
265 ms |
58860 KB |
Output is correct |
5 |
Correct |
1073 ms |
59780 KB |
Output is correct |
6 |
Correct |
735 ms |
58448 KB |
Output is correct |
7 |
Correct |
1020 ms |
59684 KB |
Output is correct |
8 |
Correct |
662 ms |
58696 KB |
Output is correct |
9 |
Correct |
800 ms |
59704 KB |
Output is correct |
10 |
Correct |
1051 ms |
61384 KB |
Output is correct |
11 |
Correct |
875 ms |
61236 KB |
Output is correct |
12 |
Correct |
1113 ms |
61184 KB |
Output is correct |
13 |
Correct |
757 ms |
59672 KB |
Output is correct |
14 |
Correct |
813 ms |
60604 KB |
Output is correct |
15 |
Correct |
1016 ms |
61368 KB |
Output is correct |
16 |
Correct |
691 ms |
61380 KB |
Output is correct |
17 |
Correct |
22 ms |
58192 KB |
Output is correct |
18 |
Correct |
25 ms |
58164 KB |
Output is correct |
19 |
Correct |
23 ms |
58192 KB |
Output is correct |
20 |
Correct |
24 ms |
58176 KB |
Output is correct |
21 |
Correct |
24 ms |
58212 KB |
Output is correct |
22 |
Correct |
24 ms |
58192 KB |
Output is correct |
23 |
Correct |
24 ms |
58116 KB |
Output is correct |
24 |
Correct |
24 ms |
58124 KB |
Output is correct |
25 |
Correct |
25 ms |
58192 KB |
Output is correct |
26 |
Correct |
27 ms |
58192 KB |
Output is correct |
27 |
Correct |
46 ms |
58108 KB |
Output is correct |
28 |
Correct |
45 ms |
58288 KB |
Output is correct |
29 |
Correct |
42 ms |
58192 KB |
Output is correct |
30 |
Correct |
40 ms |
58144 KB |
Output is correct |
31 |
Correct |
32 ms |
58216 KB |
Output is correct |
32 |
Correct |
23 ms |
58180 KB |
Output is correct |
33 |
Correct |
43 ms |
59132 KB |
Output is correct |
34 |
Correct |
63 ms |
59720 KB |
Output is correct |
35 |
Correct |
70 ms |
61096 KB |
Output is correct |
36 |
Correct |
57 ms |
59696 KB |
Output is correct |
37 |
Correct |
56 ms |
60572 KB |
Output is correct |
38 |
Correct |
57 ms |
61372 KB |
Output is correct |
39 |
Correct |
22 ms |
58164 KB |
Output is correct |
40 |
Correct |
23 ms |
58192 KB |
Output is correct |
41 |
Correct |
21 ms |
58192 KB |
Output is correct |
42 |
Correct |
288 ms |
58936 KB |
Output is correct |
43 |
Correct |
1020 ms |
59788 KB |
Output is correct |
44 |
Correct |
680 ms |
58448 KB |
Output is correct |
45 |
Correct |
722 ms |
59704 KB |
Output is correct |
46 |
Correct |
385 ms |
58708 KB |
Output is correct |
47 |
Correct |
713 ms |
59720 KB |
Output is correct |
48 |
Correct |
981 ms |
61364 KB |
Output is correct |
49 |
Correct |
817 ms |
61220 KB |
Output is correct |
50 |
Correct |
1030 ms |
61096 KB |
Output is correct |
51 |
Correct |
833 ms |
59672 KB |
Output is correct |
52 |
Correct |
985 ms |
60488 KB |
Output is correct |
53 |
Correct |
1002 ms |
61376 KB |
Output is correct |
54 |
Correct |
1008 ms |
61344 KB |
Output is correct |
55 |
Correct |
23 ms |
58192 KB |
Output is correct |
56 |
Correct |
107 ms |
59700 KB |
Output is correct |
57 |
Correct |
917 ms |
59788 KB |
Output is correct |
58 |
Correct |
533 ms |
58484 KB |
Output is correct |
59 |
Correct |
858 ms |
59680 KB |
Output is correct |
60 |
Correct |
420 ms |
58776 KB |
Output is correct |
61 |
Correct |
921 ms |
59708 KB |
Output is correct |
62 |
Correct |
863 ms |
61384 KB |
Output is correct |
63 |
Correct |
857 ms |
60976 KB |
Output is correct |
64 |
Correct |
1061 ms |
60724 KB |
Output is correct |
65 |
Correct |
696 ms |
59724 KB |
Output is correct |
66 |
Correct |
1037 ms |
60520 KB |
Output is correct |
67 |
Correct |
935 ms |
61432 KB |
Output is correct |
68 |
Correct |
960 ms |
61364 KB |
Output is correct |
69 |
Correct |
22 ms |
58192 KB |
Output is correct |
70 |
Correct |
23 ms |
58176 KB |
Output is correct |
71 |
Correct |
23 ms |
58088 KB |
Output is correct |
72 |
Correct |
24 ms |
58132 KB |
Output is correct |
73 |
Correct |
24 ms |
58136 KB |
Output is correct |
74 |
Correct |
23 ms |
58124 KB |
Output is correct |
75 |
Correct |
24 ms |
58204 KB |
Output is correct |
76 |
Correct |
22 ms |
58108 KB |
Output is correct |
77 |
Correct |
22 ms |
58116 KB |
Output is correct |
78 |
Correct |
24 ms |
58128 KB |
Output is correct |
79 |
Correct |
25 ms |
58148 KB |
Output is correct |
80 |
Correct |
28 ms |
58228 KB |
Output is correct |
81 |
Correct |
24 ms |
58116 KB |
Output is correct |
82 |
Correct |
28 ms |
58232 KB |
Output is correct |
83 |
Correct |
24 ms |
58164 KB |
Output is correct |
84 |
Correct |
26 ms |
58192 KB |
Output is correct |
85 |
Correct |
26 ms |
58148 KB |
Output is correct |
86 |
Correct |
39 ms |
58120 KB |
Output is correct |
87 |
Correct |
37 ms |
58192 KB |
Output is correct |
88 |
Correct |
39 ms |
58172 KB |
Output is correct |
89 |
Correct |
42 ms |
58248 KB |
Output is correct |
90 |
Correct |
37 ms |
58192 KB |
Output is correct |
91 |
Correct |
22 ms |
58192 KB |
Output is correct |
92 |
Correct |
23 ms |
58132 KB |
Output is correct |
93 |
Correct |
39 ms |
58192 KB |
Output is correct |
94 |
Correct |
43 ms |
58208 KB |
Output is correct |
95 |
Correct |
37 ms |
58164 KB |
Output is correct |
96 |
Correct |
40 ms |
58128 KB |
Output is correct |
97 |
Correct |
38 ms |
58192 KB |
Output is correct |
98 |
Correct |
22 ms |
58188 KB |
Output is correct |
99 |
Correct |
66 ms |
59680 KB |
Output is correct |
100 |
Correct |
59 ms |
59788 KB |
Output is correct |
101 |
Correct |
52 ms |
60956 KB |
Output is correct |
102 |
Correct |
58 ms |
59816 KB |
Output is correct |
103 |
Correct |
53 ms |
60612 KB |
Output is correct |
104 |
Correct |
55 ms |
61344 KB |
Output is correct |
105 |
Correct |
22 ms |
58144 KB |
Output is correct |
106 |
Correct |
43 ms |
59092 KB |
Output is correct |
107 |
Correct |
59 ms |
59680 KB |
Output is correct |
108 |
Correct |
52 ms |
61092 KB |
Output is correct |
109 |
Correct |
67 ms |
59688 KB |
Output is correct |
110 |
Correct |
52 ms |
60540 KB |
Output is correct |
111 |
Correct |
54 ms |
61356 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
23 ms |
58192 KB |
Output is correct |
2 |
Correct |
22 ms |
58192 KB |
Output is correct |
3 |
Correct |
132 ms |
60692 KB |
Output is correct |
4 |
Correct |
1185 ms |
61344 KB |
Output is correct |
5 |
Correct |
922 ms |
59764 KB |
Output is correct |
6 |
Correct |
1039 ms |
61348 KB |
Output is correct |
7 |
Correct |
661 ms |
60352 KB |
Output is correct |
8 |
Correct |
1024 ms |
61384 KB |
Output is correct |
9 |
Correct |
23 ms |
58184 KB |
Output is correct |
10 |
Correct |
21 ms |
58088 KB |
Output is correct |
11 |
Correct |
21 ms |
58192 KB |
Output is correct |
12 |
Correct |
21 ms |
58136 KB |
Output is correct |
13 |
Correct |
22 ms |
58124 KB |
Output is correct |
14 |
Incorrect |
24 ms |
58208 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |