#include <bits/stdc++.h>
#include "jumps.h"
using namespace std;
using ll = long long;
vector<ll> seg, br, d; ll n;
ll qw(ll a, ll b) {
b++;
ll ans = 0;
for (a += n, b += n; a < b; a /= 2, b /= 2) {
if (a % 2) {
ans = max(ans, seg[a]);
a++;
}
if (b % 2) {
b--;
ans = max(ans, seg[b]);
}
}
return ans;
}
ll ind(ll v, ll a, ll b) {
if (a == b) {
return a;
}
ll m = (a + b) / 2;
if (qw(a, m) >= v) {
return ind(v, a, m);
}
return ind(v, m + 1, b);
}
void init(int N, std::vector<int> H) {
n = N;
seg = vector<ll>(2 * n + 1, 0);
//segment setup
for (ll i = 0; i < n; i++) {
seg[i + n] = H[i];
}
for (ll i = n - 1; i > 0; i--) {
seg[i] = max(seg[2 * i], seg[2 * i + 1]);
}
//br setup
br = vector<ll>(n, 0); for (ll i = 0; i < n; i++) { br[i] = i + 1; }
for (ll i = n - 1; i >= 0; i--) {
ll j = i;
while (br[j] != n) {
if (H[i] < H[br[j]]) {
break;
}
j = br[j];
}
br[i] = br[j];
}
//distance
d = vector<ll>(n + 1); d[n] = 0;
for (ll i = n - 1; i >= 0; i--) {
d[i] = d[br[i]] + 1;
}
}
//ind,qw,d
int minimum_jumps(int A, int B, int C, int D) {
if (B == C) {
return 0;
}
ll w=qw(B,C-1);
ll x = ind(w, C, D);
if (d[B] > d[x]) {
return d[B] - d[x];
}
return -1;
}
/*#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
ll n; cin >> n;
vector<ll> a(n), r(n);
for (ll i = 0; i < n; i++) {
cin >> a[i];
r[i] = i - 1;
}
for (ll i = 0; i < n; i++) {
ll j = i;
while (r[j] != -1) {
if (a[i] > a[r[j]]) {
break;
}
j = r[j];
}
r[i] = r[j];
cout << r[i] + 1 << '\n';
}
}*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
131 ms |
6424 KB |
Output is correct |
4 |
Correct |
745 ms |
8092 KB |
Output is correct |
5 |
Correct |
818 ms |
4136 KB |
Output is correct |
6 |
Correct |
863 ms |
8008 KB |
Output is correct |
7 |
Correct |
873 ms |
5528 KB |
Output is correct |
8 |
Correct |
1002 ms |
8124 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
1 ms |
208 KB |
Output is correct |
4 |
Correct |
0 ms |
208 KB |
Output is correct |
5 |
Incorrect |
1 ms |
208 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
1 ms |
208 KB |
Output is correct |
4 |
Correct |
0 ms |
208 KB |
Output is correct |
5 |
Incorrect |
1 ms |
208 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
0 ms |
208 KB |
Output is correct |
4 |
Correct |
0 ms |
208 KB |
Output is correct |
5 |
Incorrect |
19 ms |
6556 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
1 ms |
208 KB |
Output is correct |
4 |
Incorrect |
242 ms |
3868 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
1 ms |
208 KB |
Output is correct |
4 |
Incorrect |
242 ms |
3868 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
131 ms |
6424 KB |
Output is correct |
4 |
Correct |
745 ms |
8092 KB |
Output is correct |
5 |
Correct |
818 ms |
4136 KB |
Output is correct |
6 |
Correct |
863 ms |
8008 KB |
Output is correct |
7 |
Correct |
873 ms |
5528 KB |
Output is correct |
8 |
Correct |
1002 ms |
8124 KB |
Output is correct |
9 |
Correct |
0 ms |
208 KB |
Output is correct |
10 |
Correct |
0 ms |
208 KB |
Output is correct |
11 |
Correct |
1 ms |
208 KB |
Output is correct |
12 |
Correct |
0 ms |
208 KB |
Output is correct |
13 |
Incorrect |
1 ms |
208 KB |
Output isn't correct |
14 |
Halted |
0 ms |
0 KB |
- |