답안 #1052393

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1052393 2024-08-10T14:14:28 Z erray Escape Route 2 (JOI24_escape2) C++17
54 / 100
3000 ms 30760 KB
#include <bits/stdc++.h>

using namespace std;

#ifdef DEBUG 
  #include "/home/hp/contests/joi24scd4/debug.h"
#else 
  #define debug(...) void(37)
#endif

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int N, T;
  cin >> N >> T;
  vector<vector<array<int, 2>>> g(N);
  for (int i = 0; i < N - 1; ++i) {
    int M;
    cin >> M;
    vector<int> A(M), B(M);
    for (int j = 0; j < M; ++j) {
      cin >> A[j] >> B[j];
    }
    vector<int> ord(M);
    iota(ord.begin(), ord.end(), 0);
    sort(ord.begin(), ord.end(), [&](int x, int y) {
      return A[x] < A[y];
    });
    vector<int> st;
    for (auto x:  ord) {
      while (!st.empty() && B[st.back()] >= B[x]) {
        st.pop_back();
      }
      st.push_back(x);
    }
    for (auto x : st) {
      g[i].push_back({A[x], B[x]});
    }
  }
  vector<int> pref(N + 1);
  vector<array<int, 2>> info;
  for (int i = 0; i < N; ++i) {
    pref[i + 1] = pref[i] + int(g[i].size());
    for (auto x : g[i]) {
      info.push_back(x);
    }
  }
  debug(g, pref, info);
  auto Id = [&](int i, int j) {
    assert(j < int(g[i].size()));
    return pref[i] + j;
  };
  auto Next = [&](int i, int t) -> array<int, 2> {
    int ind = lower_bound(g[i].begin(), g[i].end(), array<int, 2>{t, -1}) - g[i].begin();
    if (ind == int(g[i].size())) {
      return {0, 1};
    } else {
      return {ind, 0};
    }
  };
  
  int s = pref[N];
  int LG = __lg(N) + 1;
  vector<vector<int>> lift(LG, vector<int>(s, -1));
  vector<vector<int>> cost(LG, vector<int>(s));
  for (int i = 0; i < N - 2; ++i) {
    for (int j = 0; j < int(g[i].size()); ++j) {
      auto[to, _cost] = Next(i + 1, g[i][j][1]);
      lift[0][Id(i, j)] = Id(i + 1, to);
      cost[0][Id(i, j)] = _cost;
    }
  }
  for (int l = 1; l < LG; ++l) {
    for (int i = 0; i < s; ++i) {
      int to = lift[l - 1][i];
      if (to == -1) {
        lift[l][i] = -1;
      } else {
        lift[l][i] = lift[l - 1][to];
        cost[l][i] = cost[l - 1][i] + cost[l - 1][to];
      }
    }
  }
  auto Find_dist = [&](int v, int dist) -> int64_t {
    int days = 0;
    int start = info[v][0];
    for (int i = 0; dist > 0; ++i, dist >>= 1) {
      if (dist % 2) {
        days += cost[i][v];
        v = lift[i][v];
      }
    }
    return 1LL * days * T + info[v][1] - start;
  };
  
  debug(lift, cost);
  int Q;
  cin >> Q;
  while (Q--) {
    int L, R;
    cin >> L >> R;
    --L, --R;
    int64_t ans = int64_t(1e18);
    for (int j = 0; j < int(g[L].size()); ++j) {
      ans = min(ans, Find_dist(Id(L, j), R - L - 1));
    }
    cout << ans << '\n';
  }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 60 ms 4512 KB Output is correct
3 Correct 38 ms 5460 KB Output is correct
4 Correct 54 ms 7252 KB Output is correct
5 Correct 77 ms 5716 KB Output is correct
6 Correct 51 ms 7336 KB Output is correct
7 Correct 71 ms 7132 KB Output is correct
8 Correct 42 ms 5396 KB Output is correct
9 Correct 51 ms 7276 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 60 ms 4512 KB Output is correct
3 Correct 38 ms 5460 KB Output is correct
4 Correct 54 ms 7252 KB Output is correct
5 Correct 77 ms 5716 KB Output is correct
6 Correct 51 ms 7336 KB Output is correct
7 Correct 71 ms 7132 KB Output is correct
8 Correct 42 ms 5396 KB Output is correct
9 Correct 51 ms 7276 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 51 ms 6316 KB Output is correct
12 Correct 67 ms 6252 KB Output is correct
13 Correct 51 ms 6256 KB Output is correct
14 Correct 56 ms 6112 KB Output is correct
15 Correct 52 ms 6736 KB Output is correct
16 Correct 33 ms 4544 KB Output is correct
17 Correct 51 ms 6884 KB Output is correct
18 Correct 52 ms 6580 KB Output is correct
19 Correct 65 ms 6996 KB Output is correct
20 Correct 52 ms 6484 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 60 ms 4512 KB Output is correct
3 Correct 38 ms 5460 KB Output is correct
4 Correct 54 ms 7252 KB Output is correct
5 Correct 77 ms 5716 KB Output is correct
6 Correct 51 ms 7336 KB Output is correct
7 Correct 71 ms 7132 KB Output is correct
8 Correct 42 ms 5396 KB Output is correct
9 Correct 51 ms 7276 KB Output is correct
10 Correct 105 ms 23436 KB Output is correct
11 Correct 154 ms 30760 KB Output is correct
12 Correct 167 ms 30664 KB Output is correct
13 Correct 111 ms 28616 KB Output is correct
14 Correct 139 ms 30664 KB Output is correct
15 Correct 133 ms 30664 KB Output is correct
16 Correct 91 ms 23496 KB Output is correct
17 Correct 135 ms 30664 KB Output is correct
18 Correct 74 ms 22984 KB Output is correct
19 Correct 51 ms 22500 KB Output is correct
20 Correct 56 ms 22984 KB Output is correct
21 Correct 56 ms 22960 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 60 ms 4512 KB Output is correct
3 Correct 38 ms 5460 KB Output is correct
4 Correct 54 ms 7252 KB Output is correct
5 Correct 77 ms 5716 KB Output is correct
6 Correct 51 ms 7336 KB Output is correct
7 Correct 71 ms 7132 KB Output is correct
8 Correct 42 ms 5396 KB Output is correct
9 Correct 51 ms 7276 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 51 ms 6316 KB Output is correct
12 Correct 67 ms 6252 KB Output is correct
13 Correct 51 ms 6256 KB Output is correct
14 Correct 56 ms 6112 KB Output is correct
15 Correct 52 ms 6736 KB Output is correct
16 Correct 33 ms 4544 KB Output is correct
17 Correct 51 ms 6884 KB Output is correct
18 Correct 52 ms 6580 KB Output is correct
19 Correct 65 ms 6996 KB Output is correct
20 Correct 52 ms 6484 KB Output is correct
21 Correct 105 ms 23436 KB Output is correct
22 Correct 154 ms 30760 KB Output is correct
23 Correct 167 ms 30664 KB Output is correct
24 Correct 111 ms 28616 KB Output is correct
25 Correct 139 ms 30664 KB Output is correct
26 Correct 133 ms 30664 KB Output is correct
27 Correct 91 ms 23496 KB Output is correct
28 Correct 135 ms 30664 KB Output is correct
29 Correct 74 ms 22984 KB Output is correct
30 Correct 51 ms 22500 KB Output is correct
31 Correct 56 ms 22984 KB Output is correct
32 Correct 56 ms 22960 KB Output is correct
33 Correct 137 ms 24532 KB Output is correct
34 Correct 156 ms 24428 KB Output is correct
35 Correct 133 ms 22728 KB Output is correct
36 Correct 138 ms 22860 KB Output is correct
37 Correct 125 ms 23756 KB Output is correct
38 Correct 103 ms 21704 KB Output is correct
39 Correct 136 ms 28584 KB Output is correct
40 Correct 121 ms 19148 KB Output is correct
41 Correct 114 ms 20440 KB Output is correct
42 Correct 121 ms 27100 KB Output is correct
43 Correct 107 ms 20336 KB Output is correct
44 Correct 116 ms 21864 KB Output is correct
45 Correct 70 ms 20520 KB Output is correct
46 Correct 59 ms 18176 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 172 ms 12240 KB Output is correct
4 Correct 179 ms 12244 KB Output is correct
5 Correct 202 ms 12308 KB Output is correct
6 Correct 178 ms 12244 KB Output is correct
7 Correct 174 ms 12244 KB Output is correct
8 Correct 102 ms 7884 KB Output is correct
9 Correct 172 ms 12504 KB Output is correct
10 Execution timed out 3065 ms 4472 KB Time limit exceeded
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 60 ms 4512 KB Output is correct
3 Correct 38 ms 5460 KB Output is correct
4 Correct 54 ms 7252 KB Output is correct
5 Correct 77 ms 5716 KB Output is correct
6 Correct 51 ms 7336 KB Output is correct
7 Correct 71 ms 7132 KB Output is correct
8 Correct 42 ms 5396 KB Output is correct
9 Correct 51 ms 7276 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 51 ms 6316 KB Output is correct
12 Correct 67 ms 6252 KB Output is correct
13 Correct 51 ms 6256 KB Output is correct
14 Correct 56 ms 6112 KB Output is correct
15 Correct 52 ms 6736 KB Output is correct
16 Correct 33 ms 4544 KB Output is correct
17 Correct 51 ms 6884 KB Output is correct
18 Correct 52 ms 6580 KB Output is correct
19 Correct 65 ms 6996 KB Output is correct
20 Correct 52 ms 6484 KB Output is correct
21 Correct 105 ms 23436 KB Output is correct
22 Correct 154 ms 30760 KB Output is correct
23 Correct 167 ms 30664 KB Output is correct
24 Correct 111 ms 28616 KB Output is correct
25 Correct 139 ms 30664 KB Output is correct
26 Correct 133 ms 30664 KB Output is correct
27 Correct 91 ms 23496 KB Output is correct
28 Correct 135 ms 30664 KB Output is correct
29 Correct 74 ms 22984 KB Output is correct
30 Correct 51 ms 22500 KB Output is correct
31 Correct 56 ms 22984 KB Output is correct
32 Correct 56 ms 22960 KB Output is correct
33 Correct 137 ms 24532 KB Output is correct
34 Correct 156 ms 24428 KB Output is correct
35 Correct 133 ms 22728 KB Output is correct
36 Correct 138 ms 22860 KB Output is correct
37 Correct 125 ms 23756 KB Output is correct
38 Correct 103 ms 21704 KB Output is correct
39 Correct 136 ms 28584 KB Output is correct
40 Correct 121 ms 19148 KB Output is correct
41 Correct 114 ms 20440 KB Output is correct
42 Correct 121 ms 27100 KB Output is correct
43 Correct 107 ms 20336 KB Output is correct
44 Correct 116 ms 21864 KB Output is correct
45 Correct 70 ms 20520 KB Output is correct
46 Correct 59 ms 18176 KB Output is correct
47 Correct 1 ms 348 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 172 ms 12240 KB Output is correct
50 Correct 179 ms 12244 KB Output is correct
51 Correct 202 ms 12308 KB Output is correct
52 Correct 178 ms 12244 KB Output is correct
53 Correct 174 ms 12244 KB Output is correct
54 Correct 102 ms 7884 KB Output is correct
55 Correct 172 ms 12504 KB Output is correct
56 Execution timed out 3065 ms 4472 KB Time limit exceeded
57 Halted 0 ms 0 KB -