# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
24326 | 2017-06-05T12:33:04 Z | jiaqiyang | Railway Trip (JOI17_railway_trip) | C++14 | 396 ms | 17524 KB |
#include <cstdio> #include <tuple> #include <algorithm> const int N = 100000 + 10; int n, a[N]; std::pair<int, int> f[20][N]; int init() { int q; scanf("%d%*d%d", &n, &q); for (int i = 1; i <= n; ++i) scanf("%d", &a[i]); static int stk[N]; f[0][n].second = n; for (int i = 1, top = 0; i <= n; ++i) { for (; top && a[i] >= a[stk[top]]; --top) f[0][stk[top]].second = i; stk[++top] = i; } f[0][1].first = 1; for (int i = n, top = 0; i > 0; --i) { for (; top && a[i] >= a[stk[top]]; --top) f[0][stk[top]].first = i; stk[++top] = i; } for (int i = 1; i < 20; ++i) { for (int j = 1; j <= n; ++j) { int x, y; std::tie(x, y) = f[i - 1][j]; f[i][j] = {std::min(f[i - 1][x].first, f[i - 1][y].first), std::max(f[i - 1][x].second, f[i - 1][y].second)}; } } return q; } int main() { for (int q = init(); q--;) { int l, r; scanf("%d%d", &l, &r); if (l > r) std::swap(l, r); int ans = 0, x = l, y = l; for (int i = 19; i >= 0; --i) { if (std::max(f[i][x].second, f[i][y].second) >= r) continue; ans += 1 << i; std::tie(x, y) = std::make_tuple(std::min(f[i][x].first, f[i][y].first), std::max(f[i][x].second, f[i][y].second)); } l = y; x = y = r; for (int i = 19; i >= 0; --i) { if (std::min(f[i][x].first, f[i][y].first) <= l) continue; ans += 1 << i; std::tie(x, y) = std::make_tuple(std::min(f[i][x].first, f[i][y].first), std::max(f[i][x].second, f[i][y].second)); } printf("%d\n", ans); } return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 17524 KB | Output is correct |
2 | Correct | 0 ms | 17524 KB | Output is correct |
3 | Correct | 0 ms | 17524 KB | Output is correct |
4 | Correct | 0 ms | 17524 KB | Output is correct |
5 | Correct | 0 ms | 17524 KB | Output is correct |
6 | Correct | 0 ms | 17524 KB | Output is correct |
7 | Correct | 0 ms | 17524 KB | Output is correct |
8 | Correct | 0 ms | 17524 KB | Output is correct |
9 | Correct | 0 ms | 17524 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 17524 KB | Output is correct |
2 | Correct | 19 ms | 17524 KB | Output is correct |
3 | Correct | 23 ms | 17524 KB | Output is correct |
4 | Correct | 19 ms | 17524 KB | Output is correct |
5 | Correct | 23 ms | 17524 KB | Output is correct |
6 | Correct | 23 ms | 17524 KB | Output is correct |
7 | Correct | 26 ms | 17524 KB | Output is correct |
8 | Correct | 9 ms | 17524 KB | Output is correct |
9 | Correct | 16 ms | 17524 KB | Output is correct |
10 | Correct | 16 ms | 17524 KB | Output is correct |
11 | Correct | 26 ms | 17524 KB | Output is correct |
12 | Correct | 26 ms | 17524 KB | Output is correct |
13 | Correct | 23 ms | 17524 KB | Output is correct |
14 | Correct | 36 ms | 17524 KB | Output is correct |
15 | Correct | 26 ms | 17524 KB | Output is correct |
16 | Correct | 26 ms | 17524 KB | Output is correct |
17 | Correct | 26 ms | 17524 KB | Output is correct |
18 | Correct | 29 ms | 17524 KB | Output is correct |
19 | Correct | 29 ms | 17524 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 316 ms | 17524 KB | Output is correct |
2 | Correct | 299 ms | 17524 KB | Output is correct |
3 | Correct | 279 ms | 17524 KB | Output is correct |
4 | Correct | 236 ms | 17524 KB | Output is correct |
5 | Correct | 226 ms | 17524 KB | Output is correct |
6 | Correct | 269 ms | 17524 KB | Output is correct |
7 | Correct | 253 ms | 17524 KB | Output is correct |
8 | Correct | 296 ms | 17524 KB | Output is correct |
9 | Correct | 396 ms | 17524 KB | Output is correct |
10 | Correct | 343 ms | 17524 KB | Output is correct |
11 | Correct | 363 ms | 17524 KB | Output is correct |
12 | Correct | 276 ms | 17524 KB | Output is correct |
13 | Correct | 349 ms | 17524 KB | Output is correct |
14 | Correct | 276 ms | 17524 KB | Output is correct |
15 | Correct | 159 ms | 17524 KB | Output is correct |
16 | Correct | 219 ms | 17524 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 176 ms | 17524 KB | Output is correct |
2 | Correct | 199 ms | 17524 KB | Output is correct |
3 | Correct | 159 ms | 17524 KB | Output is correct |
4 | Correct | 149 ms | 17524 KB | Output is correct |
5 | Correct | 303 ms | 17524 KB | Output is correct |
6 | Correct | 259 ms | 17524 KB | Output is correct |
7 | Correct | 303 ms | 17524 KB | Output is correct |
8 | Correct | 303 ms | 17524 KB | Output is correct |
9 | Correct | 299 ms | 17524 KB | Output is correct |
10 | Correct | 269 ms | 17524 KB | Output is correct |
11 | Correct | 283 ms | 17524 KB | Output is correct |
12 | Correct | 266 ms | 17524 KB | Output is correct |
13 | Correct | 263 ms | 17524 KB | Output is correct |
14 | Correct | 179 ms | 17524 KB | Output is correct |
15 | Correct | 206 ms | 17524 KB | Output is correct |
16 | Correct | 293 ms | 17524 KB | Output is correct |
17 | Correct | 223 ms | 17524 KB | Output is correct |
18 | Correct | 276 ms | 17524 KB | Output is correct |
19 | Correct | 243 ms | 17524 KB | Output is correct |
20 | Correct | 213 ms | 17524 KB | Output is correct |
21 | Correct | 143 ms | 17524 KB | Output is correct |
22 | Correct | 203 ms | 17524 KB | Output is correct |
23 | Correct | 209 ms | 17524 KB | Output is correct |