#include "game.h"
#include <bits/stdc++.h>
using namespace std;
const int shift = 9;
const int maxN = 3e5 + 20;
int L[maxN];
int R[maxN];
pair<int, int> range[maxN];
vector<int> adj1[maxN];
vector<int> adj2[maxN];
bool done = false;
int n, k;
void init(int _n, int _k) {
n = _n;
k = _k;
for (int i = 0; i < k; i++) {
L[i] = i;
R[i] = i + 1;
}
for (int i = k; i < n; i++) {
L[i] = 0;
R[i] = k + 1;
}
for (int i = 0; i < n; i++) {
range[i] = {0, k + 1};
}
}
void update(int u);
void push(int u) {
for (auto v: adj1[u]) {
if (L[u] > L[v]) {
L[v] = L[u];
update(v);
}
}
for (auto v: adj2[u]) {
if (R[u] < R[v]) {
R[v] = R[u];
update(v);
}
}
}
void update(int u) {
if (done) {
return;
}
if (L[u] >= R[u]) {
done = true;
return;
}
int lt = range[u].first;
int rt = range[u].second;
int mt = (lt + rt) / 2;
if (L[u] <= mt && R[u] <= mt) {
range[u] = {lt, mt};
push(u);
}
else if (L[u] > mt && R[u] > mt) {
range[u] = {mt + 1, rt};
push(u);
}
}
int add_teleporter(int u, int v) {
int val = max(L[u], (u < k ? u + 1 : 0));
if (val > L[v]) {
L[v] = val;
update(v);
}
if (R[v] < R[u]) {
R[u] = R[v];
update(u);
}
adj1[u].push_back(v);
adj2[v].push_back(u);
return done;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
14416 KB |
Output is correct |
2 |
Correct |
8 ms |
14288 KB |
Output is correct |
3 |
Correct |
8 ms |
14372 KB |
Output is correct |
4 |
Correct |
9 ms |
14416 KB |
Output is correct |
5 |
Correct |
8 ms |
14380 KB |
Output is correct |
6 |
Correct |
8 ms |
14404 KB |
Output is correct |
7 |
Correct |
8 ms |
14416 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
14416 KB |
Output is correct |
2 |
Correct |
8 ms |
14288 KB |
Output is correct |
3 |
Correct |
8 ms |
14372 KB |
Output is correct |
4 |
Correct |
9 ms |
14416 KB |
Output is correct |
5 |
Correct |
8 ms |
14380 KB |
Output is correct |
6 |
Correct |
8 ms |
14404 KB |
Output is correct |
7 |
Correct |
8 ms |
14416 KB |
Output is correct |
8 |
Correct |
8 ms |
14372 KB |
Output is correct |
9 |
Correct |
8 ms |
14288 KB |
Output is correct |
10 |
Correct |
8 ms |
14288 KB |
Output is correct |
11 |
Correct |
9 ms |
14300 KB |
Output is correct |
12 |
Correct |
8 ms |
14316 KB |
Output is correct |
13 |
Correct |
10 ms |
14316 KB |
Output is correct |
14 |
Correct |
8 ms |
14400 KB |
Output is correct |
15 |
Correct |
8 ms |
14416 KB |
Output is correct |
16 |
Correct |
8 ms |
14416 KB |
Output is correct |
17 |
Correct |
8 ms |
14416 KB |
Output is correct |
18 |
Correct |
9 ms |
14416 KB |
Output is correct |
19 |
Correct |
8 ms |
14288 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
14416 KB |
Output is correct |
2 |
Correct |
8 ms |
14288 KB |
Output is correct |
3 |
Correct |
8 ms |
14372 KB |
Output is correct |
4 |
Correct |
9 ms |
14416 KB |
Output is correct |
5 |
Correct |
8 ms |
14380 KB |
Output is correct |
6 |
Correct |
8 ms |
14404 KB |
Output is correct |
7 |
Correct |
8 ms |
14416 KB |
Output is correct |
8 |
Correct |
8 ms |
14372 KB |
Output is correct |
9 |
Correct |
8 ms |
14288 KB |
Output is correct |
10 |
Correct |
8 ms |
14288 KB |
Output is correct |
11 |
Correct |
9 ms |
14300 KB |
Output is correct |
12 |
Correct |
8 ms |
14316 KB |
Output is correct |
13 |
Correct |
10 ms |
14316 KB |
Output is correct |
14 |
Correct |
8 ms |
14400 KB |
Output is correct |
15 |
Correct |
8 ms |
14416 KB |
Output is correct |
16 |
Correct |
8 ms |
14416 KB |
Output is correct |
17 |
Correct |
8 ms |
14416 KB |
Output is correct |
18 |
Correct |
9 ms |
14416 KB |
Output is correct |
19 |
Correct |
8 ms |
14288 KB |
Output is correct |
20 |
Correct |
8 ms |
14544 KB |
Output is correct |
21 |
Correct |
8 ms |
14416 KB |
Output is correct |
22 |
Correct |
8 ms |
14416 KB |
Output is correct |
23 |
Correct |
8 ms |
14416 KB |
Output is correct |
24 |
Correct |
9 ms |
14416 KB |
Output is correct |
25 |
Correct |
9 ms |
14416 KB |
Output is correct |
26 |
Correct |
10 ms |
14416 KB |
Output is correct |
27 |
Correct |
10 ms |
14468 KB |
Output is correct |
28 |
Correct |
9 ms |
14416 KB |
Output is correct |
29 |
Correct |
11 ms |
14416 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
14416 KB |
Output is correct |
2 |
Correct |
8 ms |
14288 KB |
Output is correct |
3 |
Correct |
8 ms |
14372 KB |
Output is correct |
4 |
Correct |
9 ms |
14416 KB |
Output is correct |
5 |
Correct |
8 ms |
14380 KB |
Output is correct |
6 |
Correct |
8 ms |
14404 KB |
Output is correct |
7 |
Correct |
8 ms |
14416 KB |
Output is correct |
8 |
Correct |
8 ms |
14372 KB |
Output is correct |
9 |
Correct |
8 ms |
14288 KB |
Output is correct |
10 |
Correct |
8 ms |
14288 KB |
Output is correct |
11 |
Correct |
9 ms |
14300 KB |
Output is correct |
12 |
Correct |
8 ms |
14316 KB |
Output is correct |
13 |
Correct |
10 ms |
14316 KB |
Output is correct |
14 |
Correct |
8 ms |
14400 KB |
Output is correct |
15 |
Correct |
8 ms |
14416 KB |
Output is correct |
16 |
Correct |
8 ms |
14416 KB |
Output is correct |
17 |
Correct |
8 ms |
14416 KB |
Output is correct |
18 |
Correct |
9 ms |
14416 KB |
Output is correct |
19 |
Correct |
8 ms |
14288 KB |
Output is correct |
20 |
Correct |
8 ms |
14544 KB |
Output is correct |
21 |
Correct |
8 ms |
14416 KB |
Output is correct |
22 |
Correct |
8 ms |
14416 KB |
Output is correct |
23 |
Correct |
8 ms |
14416 KB |
Output is correct |
24 |
Correct |
9 ms |
14416 KB |
Output is correct |
25 |
Correct |
9 ms |
14416 KB |
Output is correct |
26 |
Correct |
10 ms |
14416 KB |
Output is correct |
27 |
Correct |
10 ms |
14468 KB |
Output is correct |
28 |
Correct |
9 ms |
14416 KB |
Output is correct |
29 |
Correct |
11 ms |
14416 KB |
Output is correct |
30 |
Correct |
25 ms |
15912 KB |
Output is correct |
31 |
Correct |
12 ms |
15184 KB |
Output is correct |
32 |
Correct |
25 ms |
17396 KB |
Output is correct |
33 |
Correct |
32 ms |
16760 KB |
Output is correct |
34 |
Correct |
47 ms |
19432 KB |
Output is correct |
35 |
Correct |
40 ms |
17700 KB |
Output is correct |
36 |
Correct |
49 ms |
16704 KB |
Output is correct |
37 |
Correct |
41 ms |
16688 KB |
Output is correct |
38 |
Correct |
37 ms |
16404 KB |
Output is correct |
39 |
Correct |
43 ms |
16520 KB |
Output is correct |
40 |
Correct |
40 ms |
18060 KB |
Output is correct |
41 |
Correct |
40 ms |
17224 KB |
Output is correct |
42 |
Correct |
43 ms |
16944 KB |
Output is correct |
43 |
Correct |
41 ms |
17508 KB |
Output is correct |
44 |
Correct |
41 ms |
17212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
14416 KB |
Output is correct |
2 |
Correct |
8 ms |
14288 KB |
Output is correct |
3 |
Correct |
8 ms |
14372 KB |
Output is correct |
4 |
Correct |
9 ms |
14416 KB |
Output is correct |
5 |
Correct |
8 ms |
14380 KB |
Output is correct |
6 |
Correct |
8 ms |
14404 KB |
Output is correct |
7 |
Correct |
8 ms |
14416 KB |
Output is correct |
8 |
Correct |
8 ms |
14372 KB |
Output is correct |
9 |
Correct |
8 ms |
14288 KB |
Output is correct |
10 |
Correct |
8 ms |
14288 KB |
Output is correct |
11 |
Correct |
9 ms |
14300 KB |
Output is correct |
12 |
Correct |
8 ms |
14316 KB |
Output is correct |
13 |
Correct |
10 ms |
14316 KB |
Output is correct |
14 |
Correct |
8 ms |
14400 KB |
Output is correct |
15 |
Correct |
8 ms |
14416 KB |
Output is correct |
16 |
Correct |
8 ms |
14416 KB |
Output is correct |
17 |
Correct |
8 ms |
14416 KB |
Output is correct |
18 |
Correct |
9 ms |
14416 KB |
Output is correct |
19 |
Correct |
8 ms |
14288 KB |
Output is correct |
20 |
Correct |
8 ms |
14544 KB |
Output is correct |
21 |
Correct |
8 ms |
14416 KB |
Output is correct |
22 |
Correct |
8 ms |
14416 KB |
Output is correct |
23 |
Correct |
8 ms |
14416 KB |
Output is correct |
24 |
Correct |
9 ms |
14416 KB |
Output is correct |
25 |
Correct |
9 ms |
14416 KB |
Output is correct |
26 |
Correct |
10 ms |
14416 KB |
Output is correct |
27 |
Correct |
10 ms |
14468 KB |
Output is correct |
28 |
Correct |
9 ms |
14416 KB |
Output is correct |
29 |
Correct |
11 ms |
14416 KB |
Output is correct |
30 |
Correct |
25 ms |
15912 KB |
Output is correct |
31 |
Correct |
12 ms |
15184 KB |
Output is correct |
32 |
Correct |
25 ms |
17396 KB |
Output is correct |
33 |
Correct |
32 ms |
16760 KB |
Output is correct |
34 |
Correct |
47 ms |
19432 KB |
Output is correct |
35 |
Correct |
40 ms |
17700 KB |
Output is correct |
36 |
Correct |
49 ms |
16704 KB |
Output is correct |
37 |
Correct |
41 ms |
16688 KB |
Output is correct |
38 |
Correct |
37 ms |
16404 KB |
Output is correct |
39 |
Correct |
43 ms |
16520 KB |
Output is correct |
40 |
Correct |
40 ms |
18060 KB |
Output is correct |
41 |
Correct |
40 ms |
17224 KB |
Output is correct |
42 |
Correct |
43 ms |
16944 KB |
Output is correct |
43 |
Correct |
41 ms |
17508 KB |
Output is correct |
44 |
Correct |
41 ms |
17212 KB |
Output is correct |
45 |
Correct |
263 ms |
30468 KB |
Output is correct |
46 |
Correct |
15 ms |
19480 KB |
Output is correct |
47 |
Correct |
15 ms |
19408 KB |
Output is correct |
48 |
Correct |
342 ms |
43820 KB |
Output is correct |
49 |
Correct |
255 ms |
37756 KB |
Output is correct |
50 |
Correct |
701 ms |
47860 KB |
Output is correct |
51 |
Correct |
730 ms |
44416 KB |
Output is correct |
52 |
Correct |
600 ms |
37848 KB |
Output is correct |
53 |
Correct |
749 ms |
37932 KB |
Output is correct |
54 |
Correct |
833 ms |
37696 KB |
Output is correct |
55 |
Correct |
1098 ms |
37976 KB |
Output is correct |
56 |
Correct |
1224 ms |
37704 KB |
Output is correct |
57 |
Correct |
396 ms |
31760 KB |
Output is correct |
58 |
Correct |
435 ms |
31720 KB |
Output is correct |
59 |
Correct |
453 ms |
31904 KB |
Output is correct |
60 |
Correct |
517 ms |
31716 KB |
Output is correct |
61 |
Correct |
579 ms |
31364 KB |
Output is correct |
62 |
Correct |
470 ms |
39468 KB |
Output is correct |
63 |
Correct |
378 ms |
36012 KB |
Output is correct |
64 |
Correct |
1138 ms |
58216 KB |
Output is correct |
65 |
Correct |
509 ms |
37368 KB |
Output is correct |
66 |
Correct |
424 ms |
33256 KB |
Output is correct |
67 |
Correct |
822 ms |
42188 KB |
Output is correct |
68 |
Correct |
213 ms |
28580 KB |
Output is correct |
69 |
Correct |
54 ms |
22448 KB |
Output is correct |
70 |
Correct |
721 ms |
40932 KB |
Output is correct |
71 |
Correct |
334 ms |
31328 KB |
Output is correct |
72 |
Correct |
258 ms |
27180 KB |
Output is correct |
73 |
Correct |
692 ms |
39200 KB |
Output is correct |
74 |
Correct |
1407 ms |
37356 KB |
Output is correct |
75 |
Correct |
1154 ms |
45296 KB |
Output is correct |
76 |
Correct |
848 ms |
39464 KB |
Output is correct |