Submission #1040858

# Submission time Handle Problem Language Result Execution time Memory
1040858 2024-08-01T10:53:14 Z erray Overtaking (IOI23_overtaking) C++17
100 / 100
717 ms 123052 KB
#include "overtaking.h"
#include <bits/stdc++.h>

using namespace std;

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

constexpr int64_t max_Y = int64_t(1E18 + 5);

int L, X;
vector<array<int64_t, 2>> answers;
void init(int _L, int N, std::vector<long long> T, std::vector<int> W, int _X, int M, std::vector<int> S) {
  X = _X;
  L = _L;
  vector<pair<int64_t, int>> b;
  for (int i = 0; i < N; ++i) {
    if (W[i] > X) {
      b.emplace_back(T[i], W[i] - X);
    }
  }
  N = int(b.size());
  sort(b.begin(), b.end());
  set<array<int64_t, 4>> mapping;
  {
    int64_t last = -1;
    for (int i = 0; i <= N; ++i) {
      int64_t r = (i == N ? max_Y : b[i].first);
      if (last != r) {
        int64_t l = last +1;
        mapping.insert({l, r, l, r});
        last = r;
      }
    }
  }
  for (int t = 1; t < M; ++t) {
    int len = S[t] - S[t - 1];
    sort(b.begin(), b.end());
    for (int i = 0; i < N; ++i) {
      b[i].first += 1LL * b[i].second * len;
    }
    int64_t mx = -1;
    for (int i = 0; i < N; ++i) {
      mx = max(mx, b[i].first);
      b[i].first = mx;
    }
    sort(b.begin(), b.end());
    int64_t mn = int64_t(4E18);
    for (int i = N - 1; i >= 0; --i) {
      int64_t to = b[i].first;
      int64_t from = to - 1LL * b[i].second * len;
      if (from >= mn) {
        continue;
      }
      mn = from;
      auto it = mapping.lower_bound(array<int64_t, 4>{from + 1, -1, -1, -1});
      array<int64_t, 2> range{-1, -1};
      while (it != mapping.end() && (*it)[0] <= to) {
        if ((*it)[1] <= to) {
          if (range[0] == -1) range[0] = (*it)[2];
          range[1] = (*it)[3];
          it = mapping.erase(it); 
        } else {
          auto cur = *it;
          mapping.erase(it);
          if (range[0] == -1) range[0] = cur[2];
          range[1] = to;
          assert(cur[1] == cur[3]);
          mapping.insert({to + 1, cur[1], to + 1, cur[3]});
          break;
        }
      }
      if (range[0] != -1) {
        mapping.insert({to, to, range[0], range[1]}); 
      }
    } 
  }
  for (auto[ll, rr, l, r] : mapping) {
    if (ll == rr) answers.push_back({r, ll});
    else answers.push_back({r, -1});
  }
}

long long arrival_time(long long Y) {
  int64_t ans = (*lower_bound(answers.begin(), answers.end(), array<int64_t, 2>{Y, -1}))[1];
  int64_t lost = 1LL * X * L;
  return (ans == -1 ? lost + Y : ans + lost);
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 600 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 436 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 2 ms 860 KB Output is correct
10 Correct 2 ms 860 KB Output is correct
11 Correct 3 ms 1116 KB Output is correct
12 Correct 2 ms 808 KB Output is correct
13 Correct 3 ms 860 KB Output is correct
14 Correct 3 ms 860 KB Output is correct
15 Correct 2 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 3 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 2 ms 344 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 596 KB Output is correct
24 Correct 2 ms 344 KB Output is correct
25 Correct 1 ms 436 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 3 ms 1500 KB Output is correct
33 Correct 3 ms 1500 KB Output is correct
34 Correct 3 ms 1500 KB Output is correct
35 Correct 3 ms 1500 KB Output is correct
36 Correct 3 ms 1456 KB Output is correct
37 Correct 3 ms 1500 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 2 ms 860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 600 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 2 ms 860 KB Output is correct
17 Correct 2 ms 860 KB Output is correct
18 Correct 3 ms 1116 KB Output is correct
19 Correct 2 ms 808 KB Output is correct
20 Correct 3 ms 860 KB Output is correct
21 Correct 3 ms 860 KB Output is correct
22 Correct 2 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 3 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 2 ms 344 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 1 ms 596 KB Output is correct
31 Correct 2 ms 344 KB Output is correct
32 Correct 1 ms 436 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 1 ms 348 KB Output is correct
37 Correct 1 ms 348 KB Output is correct
38 Correct 1 ms 348 KB Output is correct
39 Correct 3 ms 1500 KB Output is correct
40 Correct 3 ms 1500 KB Output is correct
41 Correct 3 ms 1500 KB Output is correct
42 Correct 3 ms 1500 KB Output is correct
43 Correct 3 ms 1456 KB Output is correct
44 Correct 3 ms 1500 KB Output is correct
45 Correct 0 ms 348 KB Output is correct
46 Correct 0 ms 348 KB Output is correct
47 Correct 2 ms 860 KB Output is correct
48 Correct 74 ms 860 KB Output is correct
49 Correct 87 ms 1108 KB Output is correct
50 Correct 105 ms 1616 KB Output is correct
51 Correct 107 ms 888 KB Output is correct
52 Correct 86 ms 976 KB Output is correct
53 Correct 92 ms 1112 KB Output is correct
54 Correct 87 ms 892 KB Output is correct
55 Correct 43 ms 344 KB Output is correct
56 Correct 74 ms 852 KB Output is correct
57 Correct 71 ms 848 KB Output is correct
58 Correct 84 ms 888 KB Output is correct
59 Correct 73 ms 848 KB Output is correct
60 Correct 76 ms 848 KB Output is correct
61 Correct 74 ms 852 KB Output is correct
62 Correct 1 ms 604 KB Output is correct
63 Correct 2 ms 600 KB Output is correct
64 Correct 34 ms 604 KB Output is correct
65 Correct 37 ms 600 KB Output is correct
66 Correct 90 ms 848 KB Output is correct
67 Correct 70 ms 604 KB Output is correct
68 Correct 71 ms 856 KB Output is correct
69 Correct 397 ms 96956 KB Output is correct
70 Correct 411 ms 95928 KB Output is correct
71 Correct 420 ms 97220 KB Output is correct
72 Correct 528 ms 72528 KB Output is correct
73 Correct 399 ms 96868 KB Output is correct
74 Correct 419 ms 97468 KB Output is correct
75 Correct 1 ms 604 KB Output is correct
76 Correct 2 ms 448 KB Output is correct
77 Correct 1 ms 604 KB Output is correct
78 Correct 278 ms 44924 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 600 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 436 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 2 ms 860 KB Output is correct
28 Correct 2 ms 860 KB Output is correct
29 Correct 3 ms 1116 KB Output is correct
30 Correct 2 ms 808 KB Output is correct
31 Correct 3 ms 860 KB Output is correct
32 Correct 3 ms 860 KB Output is correct
33 Correct 2 ms 348 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 3 ms 348 KB Output is correct
36 Correct 1 ms 348 KB Output is correct
37 Correct 2 ms 344 KB Output is correct
38 Correct 1 ms 348 KB Output is correct
39 Correct 1 ms 348 KB Output is correct
40 Correct 1 ms 348 KB Output is correct
41 Correct 1 ms 596 KB Output is correct
42 Correct 2 ms 344 KB Output is correct
43 Correct 1 ms 436 KB Output is correct
44 Correct 1 ms 348 KB Output is correct
45 Correct 1 ms 348 KB Output is correct
46 Correct 1 ms 348 KB Output is correct
47 Correct 1 ms 348 KB Output is correct
48 Correct 1 ms 348 KB Output is correct
49 Correct 1 ms 348 KB Output is correct
50 Correct 3 ms 1500 KB Output is correct
51 Correct 3 ms 1500 KB Output is correct
52 Correct 3 ms 1500 KB Output is correct
53 Correct 3 ms 1500 KB Output is correct
54 Correct 3 ms 1456 KB Output is correct
55 Correct 3 ms 1500 KB Output is correct
56 Correct 0 ms 348 KB Output is correct
57 Correct 0 ms 348 KB Output is correct
58 Correct 2 ms 860 KB Output is correct
59 Correct 74 ms 860 KB Output is correct
60 Correct 87 ms 1108 KB Output is correct
61 Correct 105 ms 1616 KB Output is correct
62 Correct 107 ms 888 KB Output is correct
63 Correct 86 ms 976 KB Output is correct
64 Correct 92 ms 1112 KB Output is correct
65 Correct 87 ms 892 KB Output is correct
66 Correct 43 ms 344 KB Output is correct
67 Correct 74 ms 852 KB Output is correct
68 Correct 71 ms 848 KB Output is correct
69 Correct 84 ms 888 KB Output is correct
70 Correct 73 ms 848 KB Output is correct
71 Correct 76 ms 848 KB Output is correct
72 Correct 74 ms 852 KB Output is correct
73 Correct 1 ms 604 KB Output is correct
74 Correct 2 ms 600 KB Output is correct
75 Correct 34 ms 604 KB Output is correct
76 Correct 37 ms 600 KB Output is correct
77 Correct 90 ms 848 KB Output is correct
78 Correct 70 ms 604 KB Output is correct
79 Correct 71 ms 856 KB Output is correct
80 Correct 397 ms 96956 KB Output is correct
81 Correct 411 ms 95928 KB Output is correct
82 Correct 420 ms 97220 KB Output is correct
83 Correct 528 ms 72528 KB Output is correct
84 Correct 399 ms 96868 KB Output is correct
85 Correct 419 ms 97468 KB Output is correct
86 Correct 1 ms 604 KB Output is correct
87 Correct 2 ms 448 KB Output is correct
88 Correct 1 ms 604 KB Output is correct
89 Correct 278 ms 44924 KB Output is correct
90 Correct 90 ms 3924 KB Output is correct
91 Correct 234 ms 36180 KB Output is correct
92 Correct 260 ms 36044 KB Output is correct
93 Correct 232 ms 36176 KB Output is correct
94 Correct 258 ms 35788 KB Output is correct
95 Correct 235 ms 36172 KB Output is correct
96 Correct 226 ms 36176 KB Output is correct
97 Correct 57 ms 3664 KB Output is correct
98 Correct 222 ms 35520 KB Output is correct
99 Correct 222 ms 36424 KB Output is correct
100 Correct 225 ms 35912 KB Output is correct
101 Correct 222 ms 35400 KB Output is correct
102 Correct 227 ms 35408 KB Output is correct
103 Correct 235 ms 35668 KB Output is correct
104 Correct 173 ms 33620 KB Output is correct
105 Correct 191 ms 38092 KB Output is correct
106 Correct 296 ms 43844 KB Output is correct
107 Correct 238 ms 43208 KB Output is correct
108 Correct 242 ms 43336 KB Output is correct
109 Correct 245 ms 43348 KB Output is correct
110 Correct 247 ms 43476 KB Output is correct
111 Correct 595 ms 122016 KB Output is correct
112 Correct 593 ms 121776 KB Output is correct
113 Correct 637 ms 123052 KB Output is correct
114 Correct 684 ms 72308 KB Output is correct
115 Correct 625 ms 121904 KB Output is correct
116 Correct 611 ms 122784 KB Output is correct
117 Correct 132 ms 39252 KB Output is correct
118 Correct 130 ms 39508 KB Output is correct
119 Correct 127 ms 37456 KB Output is correct
120 Correct 131 ms 39504 KB Output is correct
121 Correct 135 ms 40548 KB Output is correct
122 Correct 451 ms 64960 KB Output is correct
123 Correct 717 ms 70700 KB Output is correct
124 Correct 620 ms 60620 KB Output is correct
125 Correct 635 ms 65204 KB Output is correct