# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
549938 | 2022-04-16T21:48:22 Z | LucaDantas | Railway Trip (JOI17_railway_trip) | C++17 | 221 ms | 18676 KB |
#include <bits/stdc++.h> using namespace std; constexpr int maxn = 1e5+10, logn = 20; int a[maxn], l[maxn][logn], r[maxn][logn]; int main() { int n, k, q; scanf("%d %d %d", &n, &k, &q); for(int i = 1; i <= n; i++) scanf("%d", a+i); l[1][0] = 1; for(int i = 2; i <= n; i++) { l[i][0] = i-1; while(a[l[i][0]] < a[i]) l[i][0] = l[l[i][0]][0]; } r[n][0] = n; for(int i = n-1; i >= 1; i--) { r[i][0] = i+1; while(a[r[i][0]] < a[i]) r[i][0] = r[r[i][0]][0]; } for(int lg = 1; lg < logn; lg++) { for(int i = 1; i <= n; i++) { l[i][lg] = min(l[l[i][lg-1]][lg-1], l[r[i][lg-1]][lg-1]); r[i][lg] = max(r[l[i][lg-1]][lg-1], r[r[i][lg-1]][lg-1]); } } while(q--) { int x, y; scanf("%d %d", &x, &y); if(x > y) swap(x, y); int L = x, R = x, ans = 0; for(int lg = logn-1; lg >= 0; lg--) if(max(r[L][lg], r[R][lg]) < y) { ans += 1<<lg; tie(L, R) = make_pair(min(l[L][lg], l[R][lg]), max(r[L][lg], r[R][lg])); } x = R; L = y, R = y; for(int lg = logn-1; lg >= 0; lg--) if(min(l[L][lg], l[R][lg]) > x) { ans += 1<<lg; tie(L, R) = make_pair(min(l[L][lg], l[R][lg]), max(r[L][lg], r[R][lg])); } printf("%d\n", ans); } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 304 KB | Output is correct |
3 | Correct | 1 ms | 212 KB | Output is correct |
4 | Correct | 1 ms | 340 KB | Output is correct |
5 | Correct | 1 ms | 340 KB | Output is correct |
6 | Correct | 1 ms | 340 KB | Output is correct |
7 | Correct | 1 ms | 212 KB | Output is correct |
8 | Correct | 1 ms | 340 KB | Output is correct |
9 | Correct | 1 ms | 304 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 468 KB | Output is correct |
2 | Correct | 46 ms | 16536 KB | Output is correct |
3 | Correct | 48 ms | 16576 KB | Output is correct |
4 | Correct | 42 ms | 16596 KB | Output is correct |
5 | Correct | 50 ms | 16616 KB | Output is correct |
6 | Correct | 43 ms | 16724 KB | Output is correct |
7 | Correct | 44 ms | 16900 KB | Output is correct |
8 | Correct | 39 ms | 16460 KB | Output is correct |
9 | Correct | 50 ms | 16908 KB | Output is correct |
10 | Correct | 42 ms | 16708 KB | Output is correct |
11 | Correct | 49 ms | 16852 KB | Output is correct |
12 | Correct | 49 ms | 16912 KB | Output is correct |
13 | Correct | 49 ms | 16868 KB | Output is correct |
14 | Correct | 48 ms | 16844 KB | Output is correct |
15 | Correct | 49 ms | 16896 KB | Output is correct |
16 | Correct | 50 ms | 16872 KB | Output is correct |
17 | Correct | 45 ms | 16928 KB | Output is correct |
18 | Correct | 45 ms | 16844 KB | Output is correct |
19 | Correct | 45 ms | 16976 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 132 ms | 18188 KB | Output is correct |
2 | Correct | 144 ms | 18112 KB | Output is correct |
3 | Correct | 165 ms | 18116 KB | Output is correct |
4 | Correct | 128 ms | 18172 KB | Output is correct |
5 | Correct | 155 ms | 18136 KB | Output is correct |
6 | Correct | 147 ms | 18148 KB | Output is correct |
7 | Correct | 122 ms | 18124 KB | Output is correct |
8 | Correct | 173 ms | 18188 KB | Output is correct |
9 | Correct | 221 ms | 18168 KB | Output is correct |
10 | Correct | 200 ms | 18208 KB | Output is correct |
11 | Correct | 221 ms | 18360 KB | Output is correct |
12 | Correct | 196 ms | 18244 KB | Output is correct |
13 | Correct | 219 ms | 18228 KB | Output is correct |
14 | Correct | 187 ms | 18096 KB | Output is correct |
15 | Correct | 181 ms | 18076 KB | Output is correct |
16 | Correct | 147 ms | 17980 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 122 ms | 18332 KB | Output is correct |
2 | Correct | 116 ms | 18240 KB | Output is correct |
3 | Correct | 125 ms | 18256 KB | Output is correct |
4 | Correct | 112 ms | 18244 KB | Output is correct |
5 | Correct | 207 ms | 18240 KB | Output is correct |
6 | Correct | 189 ms | 18588 KB | Output is correct |
7 | Correct | 168 ms | 18612 KB | Output is correct |
8 | Correct | 175 ms | 18448 KB | Output is correct |
9 | Correct | 205 ms | 18528 KB | Output is correct |
10 | Correct | 149 ms | 18552 KB | Output is correct |
11 | Correct | 157 ms | 18508 KB | Output is correct |
12 | Correct | 173 ms | 18544 KB | Output is correct |
13 | Correct | 165 ms | 18604 KB | Output is correct |
14 | Correct | 165 ms | 18676 KB | Output is correct |
15 | Correct | 177 ms | 18572 KB | Output is correct |
16 | Correct | 191 ms | 18528 KB | Output is correct |
17 | Correct | 165 ms | 18564 KB | Output is correct |
18 | Correct | 166 ms | 18508 KB | Output is correct |
19 | Correct | 166 ms | 18488 KB | Output is correct |
20 | Correct | 136 ms | 18360 KB | Output is correct |
21 | Correct | 126 ms | 18316 KB | Output is correct |
22 | Correct | 127 ms | 18384 KB | Output is correct |
23 | Correct | 127 ms | 18232 KB | Output is correct |