| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 | 
|---|---|---|---|---|---|---|---|
| 24326 | jiaqiyang | Railway Trip (JOI17_railway_trip) | C++14 | 396 ms | 17524 KiB | 
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
}
컴파일 시 표준 에러 (stderr) 메시지
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
