#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define fi first
#define se second
#define mp make_pair
const int N = (int)2e5 + 10;
const int LOG = 18;
int n;
vector<int> H;
pii tab[LOG][N];
int LG[N];
pii get(int lf, int rf){
int ag = LG[rf - lf + 1];
return max(tab[ag][lf], tab[ag][rf - (1 << ag) + 1]);
}
int lef[N];
int rig[N];
void init(int _N, vector<int> _H) {
n = _N;
H = _H;
for(int i = 0 ; i < n; i ++ ){
tab[0][i] = mp(H[i], i);
}
vector<int> ids;
for(int i = 0 ; i < n; i ++ ){
while(!ids.empty() && H[i] > H[ids.back()]){
ids.pop_back();
}
if(!ids.empty())
lef[i] = ids.back();
else
lef[i] = -1;
ids.push_back(i);
}
ids.clear();
for(int i = n - 1; i >= 0 ; i -- ){
while(!ids.empty() && H[i] > H[ids.back()]){
ids.pop_back();
}
if(!ids.empty())
rig[i] = ids.back();
else
rig[i] = -1;
ids.push_back(i);
}
int pak = 0;
for(int i = 1; i <= n; i ++ ){
while((1 << (pak + 1)) <= i){
pak ++ ;
}
LG[i] = pak;
}
for(int lg = 1; lg < LOG; lg ++ ){
for(int i = 0 ; i < n; i ++ ){
if(i + (1 << lg) - 1 < n){
tab[lg][i] = max(tab[lg-1][i], tab[lg-1][i + (1 << (lg - 1))]);
}
}
}
}
int dep[N];
int minimum_jumps(int A, int B, int C, int D) {
pii chk = get(C, D);
pii bins = get(B, C - 1);
if(bins.fi > chk.fi) return -1;
int cur = B;
int tr;
for(int go = LOG - 1; go >= 0 ; go -- ){
tr = cur - (1 << go);
if(tr >= A){
bins = get(tr, C - 1);
if(bins.fi < chk.fi)
cur = tr;
}
}
pii ash = get(cur, B);
B = ash.se;
for(int i = 0 ; i < n; i ++ ){
dep[i] = (int)1e9;
}
dep[B] = 0;
queue<int> opt;
opt.push(B);
while(!opt.empty()){
B = opt.front();
if(B >= C && B <= D){
return dep[B];
}
opt.pop();
if(lef[B] >= 0 && dep[B] + 1 < dep[lef[B]]){
dep[lef[B]] = dep[B] + 1;
opt.push(lef[B]);
}
if(rig[B] >= 0 && dep[B] + 1 < dep[rig[B]]){
dep[rig[B]] = dep[B] + 1;
opt.push(rig[B]);
}
}
return -1;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
328 KB |
Output is correct |
2 |
Correct |
0 ms |
200 KB |
Output is correct |
3 |
Execution timed out |
4045 ms |
25232 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
328 KB |
Output is correct |
2 |
Correct |
1 ms |
328 KB |
Output is correct |
3 |
Correct |
0 ms |
200 KB |
Output is correct |
4 |
Correct |
0 ms |
328 KB |
Output is correct |
5 |
Correct |
2 ms |
328 KB |
Output is correct |
6 |
Correct |
2 ms |
328 KB |
Output is correct |
7 |
Correct |
2 ms |
328 KB |
Output is correct |
8 |
Correct |
2 ms |
328 KB |
Output is correct |
9 |
Correct |
1 ms |
328 KB |
Output is correct |
10 |
Correct |
3 ms |
328 KB |
Output is correct |
11 |
Correct |
3 ms |
328 KB |
Output is correct |
12 |
Correct |
2 ms |
328 KB |
Output is correct |
13 |
Correct |
3 ms |
328 KB |
Output is correct |
14 |
Correct |
3 ms |
328 KB |
Output is correct |
15 |
Correct |
3 ms |
328 KB |
Output is correct |
16 |
Correct |
3 ms |
328 KB |
Output is correct |
17 |
Correct |
3 ms |
328 KB |
Output is correct |
18 |
Correct |
0 ms |
200 KB |
Output is correct |
19 |
Correct |
1 ms |
328 KB |
Output is correct |
20 |
Correct |
2 ms |
328 KB |
Output is correct |
21 |
Correct |
2 ms |
328 KB |
Output is correct |
22 |
Correct |
2 ms |
328 KB |
Output is correct |
23 |
Correct |
2 ms |
328 KB |
Output is correct |
24 |
Correct |
3 ms |
328 KB |
Output is correct |
25 |
Correct |
1 ms |
328 KB |
Output is correct |
26 |
Correct |
0 ms |
328 KB |
Output is correct |
27 |
Correct |
1 ms |
328 KB |
Output is correct |
28 |
Correct |
2 ms |
328 KB |
Output is correct |
29 |
Correct |
3 ms |
328 KB |
Output is correct |
30 |
Correct |
3 ms |
328 KB |
Output is correct |
31 |
Correct |
2 ms |
328 KB |
Output is correct |
32 |
Correct |
2 ms |
328 KB |
Output is correct |
33 |
Correct |
0 ms |
328 KB |
Output is correct |
34 |
Correct |
0 ms |
328 KB |
Output is correct |
35 |
Correct |
1 ms |
328 KB |
Output is correct |
36 |
Correct |
1 ms |
328 KB |
Output is correct |
37 |
Correct |
1 ms |
328 KB |
Output is correct |
38 |
Correct |
1 ms |
328 KB |
Output is correct |
39 |
Correct |
1 ms |
328 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
328 KB |
Output is correct |
2 |
Correct |
1 ms |
328 KB |
Output is correct |
3 |
Correct |
0 ms |
200 KB |
Output is correct |
4 |
Correct |
0 ms |
328 KB |
Output is correct |
5 |
Correct |
2 ms |
328 KB |
Output is correct |
6 |
Correct |
2 ms |
328 KB |
Output is correct |
7 |
Correct |
2 ms |
328 KB |
Output is correct |
8 |
Correct |
2 ms |
328 KB |
Output is correct |
9 |
Correct |
1 ms |
328 KB |
Output is correct |
10 |
Correct |
3 ms |
328 KB |
Output is correct |
11 |
Correct |
3 ms |
328 KB |
Output is correct |
12 |
Correct |
2 ms |
328 KB |
Output is correct |
13 |
Correct |
3 ms |
328 KB |
Output is correct |
14 |
Correct |
3 ms |
328 KB |
Output is correct |
15 |
Correct |
3 ms |
328 KB |
Output is correct |
16 |
Correct |
3 ms |
328 KB |
Output is correct |
17 |
Correct |
3 ms |
328 KB |
Output is correct |
18 |
Correct |
0 ms |
200 KB |
Output is correct |
19 |
Correct |
1 ms |
328 KB |
Output is correct |
20 |
Correct |
2 ms |
328 KB |
Output is correct |
21 |
Correct |
2 ms |
328 KB |
Output is correct |
22 |
Correct |
2 ms |
328 KB |
Output is correct |
23 |
Correct |
2 ms |
328 KB |
Output is correct |
24 |
Correct |
3 ms |
328 KB |
Output is correct |
25 |
Correct |
1 ms |
328 KB |
Output is correct |
26 |
Correct |
0 ms |
328 KB |
Output is correct |
27 |
Correct |
1 ms |
328 KB |
Output is correct |
28 |
Correct |
2 ms |
328 KB |
Output is correct |
29 |
Correct |
3 ms |
328 KB |
Output is correct |
30 |
Correct |
3 ms |
328 KB |
Output is correct |
31 |
Correct |
2 ms |
328 KB |
Output is correct |
32 |
Correct |
2 ms |
328 KB |
Output is correct |
33 |
Correct |
0 ms |
328 KB |
Output is correct |
34 |
Correct |
0 ms |
328 KB |
Output is correct |
35 |
Correct |
1 ms |
328 KB |
Output is correct |
36 |
Correct |
1 ms |
328 KB |
Output is correct |
37 |
Correct |
1 ms |
328 KB |
Output is correct |
38 |
Correct |
1 ms |
328 KB |
Output is correct |
39 |
Correct |
1 ms |
328 KB |
Output is correct |
40 |
Correct |
1 ms |
328 KB |
Output is correct |
41 |
Correct |
0 ms |
328 KB |
Output is correct |
42 |
Correct |
0 ms |
200 KB |
Output is correct |
43 |
Correct |
0 ms |
328 KB |
Output is correct |
44 |
Correct |
2 ms |
328 KB |
Output is correct |
45 |
Correct |
2 ms |
328 KB |
Output is correct |
46 |
Correct |
2 ms |
328 KB |
Output is correct |
47 |
Correct |
2 ms |
328 KB |
Output is correct |
48 |
Correct |
1 ms |
328 KB |
Output is correct |
49 |
Correct |
3 ms |
328 KB |
Output is correct |
50 |
Correct |
3 ms |
328 KB |
Output is correct |
51 |
Correct |
2 ms |
328 KB |
Output is correct |
52 |
Correct |
2 ms |
328 KB |
Output is correct |
53 |
Correct |
2 ms |
328 KB |
Output is correct |
54 |
Correct |
3 ms |
328 KB |
Output is correct |
55 |
Correct |
2 ms |
328 KB |
Output is correct |
56 |
Correct |
2 ms |
328 KB |
Output is correct |
57 |
Correct |
1 ms |
328 KB |
Output is correct |
58 |
Correct |
13 ms |
456 KB |
Output is correct |
59 |
Correct |
20 ms |
584 KB |
Output is correct |
60 |
Correct |
6 ms |
456 KB |
Output is correct |
61 |
Correct |
20 ms |
584 KB |
Output is correct |
62 |
Correct |
13 ms |
328 KB |
Output is correct |
63 |
Correct |
25 ms |
584 KB |
Output is correct |
64 |
Correct |
32 ms |
584 KB |
Output is correct |
65 |
Correct |
30 ms |
584 KB |
Output is correct |
66 |
Correct |
28 ms |
584 KB |
Output is correct |
67 |
Correct |
16 ms |
584 KB |
Output is correct |
68 |
Correct |
26 ms |
584 KB |
Output is correct |
69 |
Correct |
23 ms |
584 KB |
Output is correct |
70 |
Correct |
24 ms |
584 KB |
Output is correct |
71 |
Correct |
0 ms |
200 KB |
Output is correct |
72 |
Correct |
1 ms |
328 KB |
Output is correct |
73 |
Correct |
2 ms |
328 KB |
Output is correct |
74 |
Correct |
3 ms |
328 KB |
Output is correct |
75 |
Correct |
4 ms |
328 KB |
Output is correct |
76 |
Correct |
4 ms |
328 KB |
Output is correct |
77 |
Correct |
4 ms |
328 KB |
Output is correct |
78 |
Correct |
0 ms |
328 KB |
Output is correct |
79 |
Correct |
0 ms |
328 KB |
Output is correct |
80 |
Correct |
1 ms |
328 KB |
Output is correct |
81 |
Correct |
3 ms |
328 KB |
Output is correct |
82 |
Correct |
3 ms |
328 KB |
Output is correct |
83 |
Correct |
2 ms |
328 KB |
Output is correct |
84 |
Correct |
3 ms |
328 KB |
Output is correct |
85 |
Correct |
2 ms |
328 KB |
Output is correct |
86 |
Correct |
0 ms |
328 KB |
Output is correct |
87 |
Correct |
0 ms |
328 KB |
Output is correct |
88 |
Correct |
1 ms |
328 KB |
Output is correct |
89 |
Correct |
1 ms |
328 KB |
Output is correct |
90 |
Correct |
1 ms |
328 KB |
Output is correct |
91 |
Correct |
1 ms |
328 KB |
Output is correct |
92 |
Correct |
1 ms |
328 KB |
Output is correct |
93 |
Correct |
1 ms |
328 KB |
Output is correct |
94 |
Correct |
3 ms |
328 KB |
Output is correct |
95 |
Correct |
16 ms |
584 KB |
Output is correct |
96 |
Correct |
23 ms |
584 KB |
Output is correct |
97 |
Correct |
21 ms |
584 KB |
Output is correct |
98 |
Correct |
26 ms |
584 KB |
Output is correct |
99 |
Correct |
19 ms |
584 KB |
Output is correct |
100 |
Correct |
0 ms |
328 KB |
Output is correct |
101 |
Correct |
1 ms |
456 KB |
Output is correct |
102 |
Correct |
19 ms |
584 KB |
Output is correct |
103 |
Correct |
30 ms |
584 KB |
Output is correct |
104 |
Correct |
18 ms |
584 KB |
Output is correct |
105 |
Correct |
29 ms |
584 KB |
Output is correct |
106 |
Correct |
24 ms |
612 KB |
Output is correct |
107 |
Correct |
0 ms |
328 KB |
Output is correct |
108 |
Correct |
1 ms |
456 KB |
Output is correct |
109 |
Correct |
1 ms |
584 KB |
Output is correct |
110 |
Correct |
1 ms |
584 KB |
Output is correct |
111 |
Correct |
1 ms |
584 KB |
Output is correct |
112 |
Correct |
1 ms |
584 KB |
Output is correct |
113 |
Correct |
1 ms |
584 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
328 KB |
Output is correct |
2 |
Correct |
1 ms |
200 KB |
Output is correct |
3 |
Correct |
0 ms |
328 KB |
Output is correct |
4 |
Correct |
0 ms |
328 KB |
Output is correct |
5 |
Correct |
43 ms |
24704 KB |
Output is correct |
6 |
Correct |
55 ms |
31148 KB |
Output is correct |
7 |
Correct |
25 ms |
15304 KB |
Output is correct |
8 |
Correct |
55 ms |
31144 KB |
Output is correct |
9 |
Correct |
8 ms |
4424 KB |
Output is correct |
10 |
Correct |
54 ms |
31168 KB |
Output is correct |
11 |
Correct |
49 ms |
32008 KB |
Output is correct |
12 |
Correct |
46 ms |
31756 KB |
Output is correct |
13 |
Correct |
47 ms |
31796 KB |
Output is correct |
14 |
Correct |
53 ms |
31128 KB |
Output is correct |
15 |
Correct |
47 ms |
31636 KB |
Output is correct |
16 |
Correct |
61 ms |
32016 KB |
Output is correct |
17 |
Correct |
51 ms |
31924 KB |
Output is correct |
18 |
Correct |
0 ms |
328 KB |
Output is correct |
19 |
Correct |
0 ms |
328 KB |
Output is correct |
20 |
Correct |
1 ms |
328 KB |
Output is correct |
21 |
Correct |
1 ms |
328 KB |
Output is correct |
22 |
Correct |
1 ms |
328 KB |
Output is correct |
23 |
Correct |
1 ms |
328 KB |
Output is correct |
24 |
Correct |
1 ms |
328 KB |
Output is correct |
25 |
Correct |
0 ms |
328 KB |
Output is correct |
26 |
Correct |
1 ms |
456 KB |
Output is correct |
27 |
Correct |
1 ms |
584 KB |
Output is correct |
28 |
Correct |
1 ms |
584 KB |
Output is correct |
29 |
Correct |
1 ms |
584 KB |
Output is correct |
30 |
Correct |
1 ms |
584 KB |
Output is correct |
31 |
Correct |
2 ms |
584 KB |
Output is correct |
32 |
Correct |
0 ms |
200 KB |
Output is correct |
33 |
Correct |
53 ms |
31040 KB |
Output is correct |
34 |
Correct |
53 ms |
31040 KB |
Output is correct |
35 |
Correct |
49 ms |
31796 KB |
Output is correct |
36 |
Correct |
53 ms |
31132 KB |
Output is correct |
37 |
Correct |
47 ms |
31672 KB |
Output is correct |
38 |
Correct |
47 ms |
32052 KB |
Output is correct |
39 |
Correct |
0 ms |
328 KB |
Output is correct |
40 |
Correct |
38 ms |
17432 KB |
Output is correct |
41 |
Correct |
53 ms |
31040 KB |
Output is correct |
42 |
Correct |
52 ms |
31876 KB |
Output is correct |
43 |
Correct |
65 ms |
31136 KB |
Output is correct |
44 |
Correct |
48 ms |
31668 KB |
Output is correct |
45 |
Correct |
46 ms |
32180 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
328 KB |
Output is correct |
2 |
Correct |
1 ms |
328 KB |
Output is correct |
3 |
Correct |
0 ms |
328 KB |
Output is correct |
4 |
Correct |
170 ms |
13620 KB |
Output is correct |
5 |
Correct |
844 ms |
31152 KB |
Output is correct |
6 |
Correct |
506 ms |
4788 KB |
Output is correct |
7 |
Correct |
929 ms |
31128 KB |
Output is correct |
8 |
Correct |
545 ms |
10168 KB |
Output is correct |
9 |
Correct |
892 ms |
31152 KB |
Output is correct |
10 |
Execution timed out |
4083 ms |
32052 KB |
Time limit exceeded |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
328 KB |
Output is correct |
2 |
Correct |
1 ms |
328 KB |
Output is correct |
3 |
Correct |
0 ms |
328 KB |
Output is correct |
4 |
Correct |
170 ms |
13620 KB |
Output is correct |
5 |
Correct |
844 ms |
31152 KB |
Output is correct |
6 |
Correct |
506 ms |
4788 KB |
Output is correct |
7 |
Correct |
929 ms |
31128 KB |
Output is correct |
8 |
Correct |
545 ms |
10168 KB |
Output is correct |
9 |
Correct |
892 ms |
31152 KB |
Output is correct |
10 |
Execution timed out |
4083 ms |
32052 KB |
Time limit exceeded |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
328 KB |
Output is correct |
2 |
Correct |
0 ms |
200 KB |
Output is correct |
3 |
Execution timed out |
4045 ms |
25232 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |