#include "overtaking.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define ff first
#define ss second
#define pb push_back
ll L;
ll speed;
map<ll, ll> ans; // (l, r]
void DebugMap() {
cerr << "DEBUG MAP:" << endl;
for (pll cur : ans) {
cerr << cur.ff << ' ' << cur.ss << endl;
}
cerr << "END" << endl << endl;
}
void AddRange(ll l, ll r) {
// cerr << "ADDING " << l << ' ' << r << endl;
map<ll, ll>::iterator it;
// find extension
it = ans.lower_bound(r);
if (it != ans.begin()) {
--it;
r = max(r, it->ss);
}
// check if being contained
it = ans.upper_bound(l);
if (it != ans.begin()) {
--it;
if (it->ff <= l && r <= it->ss) return;
}
// remove all that are contained
while (true) {
it = ans.lower_bound(l);
if (it == ans.end()) break;
if (l <= it->ff && it->ss <= r) {
ans.erase(it);
} else break;
}
ans[l] = r;
// DebugMap();
}
void init(int L_, int n, vector<long long> T, vector<int> W, int X, int m, vector<int> S) {
vector<ll> s(m);
for (int i = 0; i < m; i++) s[i] = S[i];
L = L_; speed = X;
vector<pll> blocks;
for (int i = 0; i < n; i++) {
if (W[i] <= speed) continue;
blocks.pb({T[i], W[i]});
}
n = blocks.size();
ll times[m][n];
for (int i = 0; i < n; i++) times[0][i] = blocks[i].ff;
for (int i = 1; i < m; i++) {
vector<pair<pll, int>> range;
ll dt = s[i] - s[i - 1];
for (int j = 0; j < n; j++) {
range.pb({{times[i - 1][j], times[i - 1][j] + blocks[j].ss * dt}, j});
}
sort(range.begin(), range.end());
ll mx = -1e18;
for (int j = 0; j < n; j++) {
mx = max(mx, range[j].ff.ss);
times[i][range[j].ss] = mx;
}
}
// for (int i = 0; i < m; i++) {
// for (int j = 0; j < n; j++) {
// cerr << times[i][j] << ' ';
// }
// cerr << endl;
// }
// cerr << endl;
for (int i = m - 1; i >= 1; i--) {
vector<pll> range;
for (int j = 0; j < n; j++) {
ll st = times[i - 1][j] - speed * s[i - 1];
ll en = times[i][j] - speed * s[i];
range.pb({st, en});
}
sort(range.begin(), range.end());
for (pll cur : range) {
AddRange(cur.ff, cur.ss);
}
}
}
long long arrival_time(long long x) {
ll res = x + L * speed;
if (ans.empty()) return res;
map<ll, ll>::iterator it = ans.lower_bound(x);
if (it != ans.begin()) {
--it;
res = max(res, it->ss + L * speed);
}
return res;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
436 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
352 KB |
Output is correct |
4 |
Correct |
0 ms |
352 KB |
Output is correct |
5 |
Correct |
1 ms |
356 KB |
Output is correct |
6 |
Correct |
1 ms |
356 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
352 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
352 KB |
Output is correct |
11 |
Correct |
1 ms |
356 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
352 KB |
Output is correct |
2 |
Correct |
0 ms |
352 KB |
Output is correct |
3 |
Correct |
1 ms |
440 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
352 KB |
Output is correct |
6 |
Correct |
1 ms |
352 KB |
Output is correct |
7 |
Correct |
1 ms |
608 KB |
Output is correct |
8 |
Correct |
1 ms |
480 KB |
Output is correct |
9 |
Correct |
1 ms |
352 KB |
Output is correct |
10 |
Correct |
1 ms |
352 KB |
Output is correct |
11 |
Correct |
1 ms |
352 KB |
Output is correct |
12 |
Correct |
1 ms |
352 KB |
Output is correct |
13 |
Correct |
1 ms |
352 KB |
Output is correct |
14 |
Correct |
1 ms |
352 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
436 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
352 KB |
Output is correct |
5 |
Correct |
0 ms |
352 KB |
Output is correct |
6 |
Correct |
1 ms |
352 KB |
Output is correct |
7 |
Correct |
0 ms |
352 KB |
Output is correct |
8 |
Correct |
1 ms |
440 KB |
Output is correct |
9 |
Correct |
4 ms |
612 KB |
Output is correct |
10 |
Correct |
4 ms |
604 KB |
Output is correct |
11 |
Correct |
4 ms |
860 KB |
Output is correct |
12 |
Correct |
4 ms |
612 KB |
Output is correct |
13 |
Correct |
4 ms |
604 KB |
Output is correct |
14 |
Correct |
3 ms |
604 KB |
Output is correct |
15 |
Correct |
3 ms |
600 KB |
Output is correct |
16 |
Correct |
3 ms |
348 KB |
Output is correct |
17 |
Correct |
3 ms |
348 KB |
Output is correct |
18 |
Correct |
3 ms |
580 KB |
Output is correct |
19 |
Correct |
3 ms |
348 KB |
Output is correct |
20 |
Correct |
3 ms |
348 KB |
Output is correct |
21 |
Correct |
2 ms |
348 KB |
Output is correct |
22 |
Correct |
2 ms |
356 KB |
Output is correct |
23 |
Correct |
2 ms |
348 KB |
Output is correct |
24 |
Correct |
2 ms |
348 KB |
Output is correct |
25 |
Correct |
2 ms |
348 KB |
Output is correct |
26 |
Correct |
3 ms |
436 KB |
Output is correct |
27 |
Correct |
2 ms |
348 KB |
Output is correct |
28 |
Correct |
2 ms |
348 KB |
Output is correct |
29 |
Correct |
2 ms |
348 KB |
Output is correct |
30 |
Correct |
2 ms |
344 KB |
Output is correct |
31 |
Correct |
2 ms |
348 KB |
Output is correct |
32 |
Correct |
3 ms |
1116 KB |
Output is correct |
33 |
Correct |
3 ms |
1128 KB |
Output is correct |
34 |
Correct |
3 ms |
1116 KB |
Output is correct |
35 |
Correct |
3 ms |
1116 KB |
Output is correct |
36 |
Correct |
4 ms |
1112 KB |
Output is correct |
37 |
Correct |
3 ms |
1116 KB |
Output is correct |
38 |
Correct |
1 ms |
344 KB |
Output is correct |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Correct |
2 ms |
604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
436 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
352 KB |
Output is correct |
5 |
Correct |
0 ms |
352 KB |
Output is correct |
6 |
Correct |
1 ms |
356 KB |
Output is correct |
7 |
Correct |
1 ms |
356 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
352 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
352 KB |
Output is correct |
12 |
Correct |
1 ms |
356 KB |
Output is correct |
13 |
Correct |
1 ms |
352 KB |
Output is correct |
14 |
Correct |
0 ms |
352 KB |
Output is correct |
15 |
Correct |
1 ms |
440 KB |
Output is correct |
16 |
Correct |
4 ms |
612 KB |
Output is correct |
17 |
Correct |
4 ms |
604 KB |
Output is correct |
18 |
Correct |
4 ms |
860 KB |
Output is correct |
19 |
Correct |
4 ms |
612 KB |
Output is correct |
20 |
Correct |
4 ms |
604 KB |
Output is correct |
21 |
Correct |
3 ms |
604 KB |
Output is correct |
22 |
Correct |
3 ms |
600 KB |
Output is correct |
23 |
Correct |
3 ms |
348 KB |
Output is correct |
24 |
Correct |
3 ms |
348 KB |
Output is correct |
25 |
Correct |
3 ms |
580 KB |
Output is correct |
26 |
Correct |
3 ms |
348 KB |
Output is correct |
27 |
Correct |
3 ms |
348 KB |
Output is correct |
28 |
Correct |
2 ms |
348 KB |
Output is correct |
29 |
Correct |
2 ms |
356 KB |
Output is correct |
30 |
Correct |
2 ms |
348 KB |
Output is correct |
31 |
Correct |
2 ms |
348 KB |
Output is correct |
32 |
Correct |
2 ms |
348 KB |
Output is correct |
33 |
Correct |
3 ms |
436 KB |
Output is correct |
34 |
Correct |
2 ms |
348 KB |
Output is correct |
35 |
Correct |
2 ms |
348 KB |
Output is correct |
36 |
Correct |
2 ms |
348 KB |
Output is correct |
37 |
Correct |
2 ms |
344 KB |
Output is correct |
38 |
Correct |
2 ms |
348 KB |
Output is correct |
39 |
Correct |
3 ms |
1116 KB |
Output is correct |
40 |
Correct |
3 ms |
1128 KB |
Output is correct |
41 |
Correct |
3 ms |
1116 KB |
Output is correct |
42 |
Correct |
3 ms |
1116 KB |
Output is correct |
43 |
Correct |
4 ms |
1112 KB |
Output is correct |
44 |
Correct |
3 ms |
1116 KB |
Output is correct |
45 |
Correct |
1 ms |
344 KB |
Output is correct |
46 |
Correct |
0 ms |
348 KB |
Output is correct |
47 |
Correct |
2 ms |
604 KB |
Output is correct |
48 |
Correct |
239 ms |
8636 KB |
Output is correct |
49 |
Correct |
273 ms |
9296 KB |
Output is correct |
50 |
Correct |
291 ms |
9436 KB |
Output is correct |
51 |
Correct |
275 ms |
9308 KB |
Output is correct |
52 |
Correct |
269 ms |
9232 KB |
Output is correct |
53 |
Correct |
301 ms |
9236 KB |
Output is correct |
54 |
Correct |
280 ms |
9500 KB |
Output is correct |
55 |
Correct |
178 ms |
8364 KB |
Output is correct |
56 |
Correct |
231 ms |
8780 KB |
Output is correct |
57 |
Correct |
249 ms |
8860 KB |
Output is correct |
58 |
Correct |
239 ms |
8820 KB |
Output is correct |
59 |
Correct |
250 ms |
8864 KB |
Output is correct |
60 |
Correct |
240 ms |
8788 KB |
Output is correct |
61 |
Correct |
241 ms |
8804 KB |
Output is correct |
62 |
Correct |
2 ms |
604 KB |
Output is correct |
63 |
Correct |
3 ms |
600 KB |
Output is correct |
64 |
Correct |
122 ms |
4568 KB |
Output is correct |
65 |
Correct |
124 ms |
4592 KB |
Output is correct |
66 |
Correct |
202 ms |
8528 KB |
Output is correct |
67 |
Correct |
255 ms |
8612 KB |
Output is correct |
68 |
Correct |
261 ms |
8612 KB |
Output is correct |
69 |
Correct |
482 ms |
70920 KB |
Output is correct |
70 |
Correct |
471 ms |
70992 KB |
Output is correct |
71 |
Correct |
470 ms |
70916 KB |
Output is correct |
72 |
Correct |
590 ms |
52744 KB |
Output is correct |
73 |
Correct |
473 ms |
70924 KB |
Output is correct |
74 |
Correct |
517 ms |
70992 KB |
Output is correct |
75 |
Correct |
1 ms |
600 KB |
Output is correct |
76 |
Correct |
2 ms |
604 KB |
Output is correct |
77 |
Correct |
1 ms |
520 KB |
Output is correct |
78 |
Correct |
311 ms |
24100 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
436 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
352 KB |
Output is correct |
5 |
Correct |
0 ms |
352 KB |
Output is correct |
6 |
Correct |
1 ms |
356 KB |
Output is correct |
7 |
Correct |
1 ms |
356 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
352 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
352 KB |
Output is correct |
12 |
Correct |
1 ms |
356 KB |
Output is correct |
13 |
Correct |
1 ms |
352 KB |
Output is correct |
14 |
Correct |
0 ms |
352 KB |
Output is correct |
15 |
Correct |
1 ms |
440 KB |
Output is correct |
16 |
Correct |
1 ms |
344 KB |
Output is correct |
17 |
Correct |
1 ms |
352 KB |
Output is correct |
18 |
Correct |
1 ms |
352 KB |
Output is correct |
19 |
Correct |
1 ms |
608 KB |
Output is correct |
20 |
Correct |
1 ms |
480 KB |
Output is correct |
21 |
Correct |
1 ms |
352 KB |
Output is correct |
22 |
Correct |
1 ms |
352 KB |
Output is correct |
23 |
Correct |
1 ms |
352 KB |
Output is correct |
24 |
Correct |
1 ms |
352 KB |
Output is correct |
25 |
Correct |
1 ms |
352 KB |
Output is correct |
26 |
Correct |
1 ms |
352 KB |
Output is correct |
27 |
Correct |
4 ms |
612 KB |
Output is correct |
28 |
Correct |
4 ms |
604 KB |
Output is correct |
29 |
Correct |
4 ms |
860 KB |
Output is correct |
30 |
Correct |
4 ms |
612 KB |
Output is correct |
31 |
Correct |
4 ms |
604 KB |
Output is correct |
32 |
Correct |
3 ms |
604 KB |
Output is correct |
33 |
Correct |
3 ms |
600 KB |
Output is correct |
34 |
Correct |
3 ms |
348 KB |
Output is correct |
35 |
Correct |
3 ms |
348 KB |
Output is correct |
36 |
Correct |
3 ms |
580 KB |
Output is correct |
37 |
Correct |
3 ms |
348 KB |
Output is correct |
38 |
Correct |
3 ms |
348 KB |
Output is correct |
39 |
Correct |
2 ms |
348 KB |
Output is correct |
40 |
Correct |
2 ms |
356 KB |
Output is correct |
41 |
Correct |
2 ms |
348 KB |
Output is correct |
42 |
Correct |
2 ms |
348 KB |
Output is correct |
43 |
Correct |
2 ms |
348 KB |
Output is correct |
44 |
Correct |
3 ms |
436 KB |
Output is correct |
45 |
Correct |
2 ms |
348 KB |
Output is correct |
46 |
Correct |
2 ms |
348 KB |
Output is correct |
47 |
Correct |
2 ms |
348 KB |
Output is correct |
48 |
Correct |
2 ms |
344 KB |
Output is correct |
49 |
Correct |
2 ms |
348 KB |
Output is correct |
50 |
Correct |
3 ms |
1116 KB |
Output is correct |
51 |
Correct |
3 ms |
1128 KB |
Output is correct |
52 |
Correct |
3 ms |
1116 KB |
Output is correct |
53 |
Correct |
3 ms |
1116 KB |
Output is correct |
54 |
Correct |
4 ms |
1112 KB |
Output is correct |
55 |
Correct |
3 ms |
1116 KB |
Output is correct |
56 |
Correct |
1 ms |
344 KB |
Output is correct |
57 |
Correct |
0 ms |
348 KB |
Output is correct |
58 |
Correct |
2 ms |
604 KB |
Output is correct |
59 |
Correct |
239 ms |
8636 KB |
Output is correct |
60 |
Correct |
273 ms |
9296 KB |
Output is correct |
61 |
Correct |
291 ms |
9436 KB |
Output is correct |
62 |
Correct |
275 ms |
9308 KB |
Output is correct |
63 |
Correct |
269 ms |
9232 KB |
Output is correct |
64 |
Correct |
301 ms |
9236 KB |
Output is correct |
65 |
Correct |
280 ms |
9500 KB |
Output is correct |
66 |
Correct |
178 ms |
8364 KB |
Output is correct |
67 |
Correct |
231 ms |
8780 KB |
Output is correct |
68 |
Correct |
249 ms |
8860 KB |
Output is correct |
69 |
Correct |
239 ms |
8820 KB |
Output is correct |
70 |
Correct |
250 ms |
8864 KB |
Output is correct |
71 |
Correct |
240 ms |
8788 KB |
Output is correct |
72 |
Correct |
241 ms |
8804 KB |
Output is correct |
73 |
Correct |
2 ms |
604 KB |
Output is correct |
74 |
Correct |
3 ms |
600 KB |
Output is correct |
75 |
Correct |
122 ms |
4568 KB |
Output is correct |
76 |
Correct |
124 ms |
4592 KB |
Output is correct |
77 |
Correct |
202 ms |
8528 KB |
Output is correct |
78 |
Correct |
255 ms |
8612 KB |
Output is correct |
79 |
Correct |
261 ms |
8612 KB |
Output is correct |
80 |
Correct |
482 ms |
70920 KB |
Output is correct |
81 |
Correct |
471 ms |
70992 KB |
Output is correct |
82 |
Correct |
470 ms |
70916 KB |
Output is correct |
83 |
Correct |
590 ms |
52744 KB |
Output is correct |
84 |
Correct |
473 ms |
70924 KB |
Output is correct |
85 |
Correct |
517 ms |
70992 KB |
Output is correct |
86 |
Correct |
1 ms |
600 KB |
Output is correct |
87 |
Correct |
2 ms |
604 KB |
Output is correct |
88 |
Correct |
1 ms |
520 KB |
Output is correct |
89 |
Correct |
311 ms |
24100 KB |
Output is correct |
90 |
Correct |
269 ms |
11828 KB |
Output is correct |
91 |
Correct |
506 ms |
44056 KB |
Output is correct |
92 |
Correct |
524 ms |
44092 KB |
Output is correct |
93 |
Correct |
495 ms |
44592 KB |
Output is correct |
94 |
Correct |
494 ms |
43840 KB |
Output is correct |
95 |
Correct |
504 ms |
44204 KB |
Output is correct |
96 |
Correct |
530 ms |
44396 KB |
Output is correct |
97 |
Correct |
197 ms |
11568 KB |
Output is correct |
98 |
Correct |
456 ms |
43348 KB |
Output is correct |
99 |
Correct |
463 ms |
44624 KB |
Output is correct |
100 |
Correct |
463 ms |
43856 KB |
Output is correct |
101 |
Correct |
464 ms |
43316 KB |
Output is correct |
102 |
Correct |
444 ms |
43348 KB |
Output is correct |
103 |
Correct |
486 ms |
43856 KB |
Output is correct |
104 |
Correct |
317 ms |
37476 KB |
Output is correct |
105 |
Correct |
346 ms |
42068 KB |
Output is correct |
106 |
Correct |
566 ms |
51284 KB |
Output is correct |
107 |
Correct |
487 ms |
50968 KB |
Output is correct |
108 |
Correct |
505 ms |
51256 KB |
Output is correct |
109 |
Correct |
495 ms |
51024 KB |
Output is correct |
110 |
Correct |
497 ms |
51268 KB |
Output is correct |
111 |
Correct |
885 ms |
106320 KB |
Output is correct |
112 |
Correct |
911 ms |
106032 KB |
Output is correct |
113 |
Correct |
1111 ms |
106732 KB |
Output is correct |
114 |
Correct |
1278 ms |
70568 KB |
Output is correct |
115 |
Correct |
1025 ms |
106320 KB |
Output is correct |
116 |
Correct |
895 ms |
107156 KB |
Output is correct |
117 |
Correct |
182 ms |
39232 KB |
Output is correct |
118 |
Correct |
182 ms |
39300 KB |
Output is correct |
119 |
Correct |
178 ms |
37456 KB |
Output is correct |
120 |
Correct |
205 ms |
39948 KB |
Output is correct |
121 |
Correct |
184 ms |
40548 KB |
Output is correct |
122 |
Correct |
652 ms |
53456 KB |
Output is correct |
123 |
Correct |
1293 ms |
70628 KB |
Output is correct |
124 |
Correct |
1174 ms |
63632 KB |
Output is correct |
125 |
Correct |
1108 ms |
61036 KB |
Output is correct |