#include <bits/stdc++.h>
using namespace std;
#include "game.h"
int N, K;
int l[300000], r[300000]; // max_to, min_from
vector<int> adj[300000], radj[300000];
int last[300000];
int res = 0;
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++) last[i] = __lg(l[i] ^ r[i]);
}
void update(int u) {
if (res == 1) return;
if (r[u] <= l[u]) return void(res = 1);
int cur = __lg(l[u] ^ r[u]);
if (cur == last[u]) return;
last[u] = cur;
for (int v : adj[u]) {
if (l[v] < l[u]) l[v] = l[u], update(v);
}
for (int v : radj[u]) {
if (r[v] > r[u]) r[v] = r[u], update(v);
}
}
int add_teleporter(int u, int v) {
if (v <= u && u < K) return 1;
if (u == v) return 0;
adj[u].emplace_back(v);
radj[v].emplace_back(u);
int val = u < K ? max(u + 1, l[u]) : l[u];
if (l[v] < val) l[v] = val, update(v);
if (r[u] > r[v]) r[u] = r[v], update(u);
return res;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
14288 KB |
Output is correct |
2 |
Correct |
10 ms |
14292 KB |
Output is correct |
3 |
Correct |
8 ms |
14416 KB |
Output is correct |
4 |
Correct |
7 ms |
14288 KB |
Output is correct |
5 |
Correct |
8 ms |
14416 KB |
Output is correct |
6 |
Correct |
8 ms |
14416 KB |
Output is correct |
7 |
Correct |
8 ms |
14416 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
14288 KB |
Output is correct |
2 |
Correct |
10 ms |
14292 KB |
Output is correct |
3 |
Correct |
8 ms |
14416 KB |
Output is correct |
4 |
Correct |
7 ms |
14288 KB |
Output is correct |
5 |
Correct |
8 ms |
14416 KB |
Output is correct |
6 |
Correct |
8 ms |
14416 KB |
Output is correct |
7 |
Correct |
8 ms |
14416 KB |
Output is correct |
8 |
Correct |
8 ms |
14288 KB |
Output is correct |
9 |
Correct |
7 ms |
14288 KB |
Output is correct |
10 |
Correct |
7 ms |
14328 KB |
Output is correct |
11 |
Correct |
8 ms |
14416 KB |
Output is correct |
12 |
Correct |
8 ms |
14416 KB |
Output is correct |
13 |
Correct |
8 ms |
14416 KB |
Output is correct |
14 |
Correct |
10 ms |
14416 KB |
Output is correct |
15 |
Correct |
9 ms |
14416 KB |
Output is correct |
16 |
Correct |
9 ms |
14420 KB |
Output is correct |
17 |
Correct |
8 ms |
14416 KB |
Output is correct |
18 |
Correct |
7 ms |
14416 KB |
Output is correct |
19 |
Correct |
9 ms |
14416 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
14288 KB |
Output is correct |
2 |
Correct |
10 ms |
14292 KB |
Output is correct |
3 |
Correct |
8 ms |
14416 KB |
Output is correct |
4 |
Correct |
7 ms |
14288 KB |
Output is correct |
5 |
Correct |
8 ms |
14416 KB |
Output is correct |
6 |
Correct |
8 ms |
14416 KB |
Output is correct |
7 |
Correct |
8 ms |
14416 KB |
Output is correct |
8 |
Correct |
8 ms |
14288 KB |
Output is correct |
9 |
Correct |
7 ms |
14288 KB |
Output is correct |
10 |
Correct |
7 ms |
14328 KB |
Output is correct |
11 |
Correct |
8 ms |
14416 KB |
Output is correct |
12 |
Correct |
8 ms |
14416 KB |
Output is correct |
13 |
Correct |
8 ms |
14416 KB |
Output is correct |
14 |
Correct |
10 ms |
14416 KB |
Output is correct |
15 |
Correct |
9 ms |
14416 KB |
Output is correct |
16 |
Correct |
9 ms |
14420 KB |
Output is correct |
17 |
Correct |
8 ms |
14416 KB |
Output is correct |
18 |
Correct |
7 ms |
14416 KB |
Output is correct |
19 |
Correct |
9 ms |
14416 KB |
Output is correct |
20 |
Correct |
8 ms |
14424 KB |
Output is correct |
21 |
Correct |
8 ms |
14420 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 |
14436 KB |
Output is correct |
25 |
Correct |
12 ms |
14480 KB |
Output is correct |
26 |
Correct |
13 ms |
14416 KB |
Output is correct |
27 |
Correct |
10 ms |
14416 KB |
Output is correct |
28 |
Correct |
9 ms |
14416 KB |
Output is correct |
29 |
Correct |
10 ms |
14416 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
14288 KB |
Output is correct |
2 |
Correct |
10 ms |
14292 KB |
Output is correct |
3 |
Correct |
8 ms |
14416 KB |
Output is correct |
4 |
Correct |
7 ms |
14288 KB |
Output is correct |
5 |
Correct |
8 ms |
14416 KB |
Output is correct |
6 |
Correct |
8 ms |
14416 KB |
Output is correct |
7 |
Correct |
8 ms |
14416 KB |
Output is correct |
8 |
Correct |
8 ms |
14288 KB |
Output is correct |
9 |
Correct |
7 ms |
14288 KB |
Output is correct |
10 |
Correct |
7 ms |
14328 KB |
Output is correct |
11 |
Correct |
8 ms |
14416 KB |
Output is correct |
12 |
Correct |
8 ms |
14416 KB |
Output is correct |
13 |
Correct |
8 ms |
14416 KB |
Output is correct |
14 |
Correct |
10 ms |
14416 KB |
Output is correct |
15 |
Correct |
9 ms |
14416 KB |
Output is correct |
16 |
Correct |
9 ms |
14420 KB |
Output is correct |
17 |
Correct |
8 ms |
14416 KB |
Output is correct |
18 |
Correct |
7 ms |
14416 KB |
Output is correct |
19 |
Correct |
9 ms |
14416 KB |
Output is correct |
20 |
Correct |
8 ms |
14424 KB |
Output is correct |
21 |
Correct |
8 ms |
14420 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 |
14436 KB |
Output is correct |
25 |
Correct |
12 ms |
14480 KB |
Output is correct |
26 |
Correct |
13 ms |
14416 KB |
Output is correct |
27 |
Correct |
10 ms |
14416 KB |
Output is correct |
28 |
Correct |
9 ms |
14416 KB |
Output is correct |
29 |
Correct |
10 ms |
14416 KB |
Output is correct |
30 |
Correct |
21 ms |
15908 KB |
Output is correct |
31 |
Correct |
13 ms |
15100 KB |
Output is correct |
32 |
Correct |
26 ms |
17536 KB |
Output is correct |
33 |
Correct |
25 ms |
16584 KB |
Output is correct |
34 |
Correct |
35 ms |
20216 KB |
Output is correct |
35 |
Correct |
43 ms |
17852 KB |
Output is correct |
36 |
Correct |
39 ms |
16572 KB |
Output is correct |
37 |
Correct |
36 ms |
16572 KB |
Output is correct |
38 |
Correct |
30 ms |
16328 KB |
Output is correct |
39 |
Correct |
32 ms |
16360 KB |
Output is correct |
40 |
Correct |
53 ms |
19972 KB |
Output is correct |
41 |
Correct |
45 ms |
17352 KB |
Output is correct |
42 |
Correct |
38 ms |
16968 KB |
Output is correct |
43 |
Correct |
49 ms |
17596 KB |
Output is correct |
44 |
Correct |
39 ms |
17340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
14288 KB |
Output is correct |
2 |
Correct |
10 ms |
14292 KB |
Output is correct |
3 |
Correct |
8 ms |
14416 KB |
Output is correct |
4 |
Correct |
7 ms |
14288 KB |
Output is correct |
5 |
Correct |
8 ms |
14416 KB |
Output is correct |
6 |
Correct |
8 ms |
14416 KB |
Output is correct |
7 |
Correct |
8 ms |
14416 KB |
Output is correct |
8 |
Correct |
8 ms |
14288 KB |
Output is correct |
9 |
Correct |
7 ms |
14288 KB |
Output is correct |
10 |
Correct |
7 ms |
14328 KB |
Output is correct |
11 |
Correct |
8 ms |
14416 KB |
Output is correct |
12 |
Correct |
8 ms |
14416 KB |
Output is correct |
13 |
Correct |
8 ms |
14416 KB |
Output is correct |
14 |
Correct |
10 ms |
14416 KB |
Output is correct |
15 |
Correct |
9 ms |
14416 KB |
Output is correct |
16 |
Correct |
9 ms |
14420 KB |
Output is correct |
17 |
Correct |
8 ms |
14416 KB |
Output is correct |
18 |
Correct |
7 ms |
14416 KB |
Output is correct |
19 |
Correct |
9 ms |
14416 KB |
Output is correct |
20 |
Correct |
8 ms |
14424 KB |
Output is correct |
21 |
Correct |
8 ms |
14420 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 |
14436 KB |
Output is correct |
25 |
Correct |
12 ms |
14480 KB |
Output is correct |
26 |
Correct |
13 ms |
14416 KB |
Output is correct |
27 |
Correct |
10 ms |
14416 KB |
Output is correct |
28 |
Correct |
9 ms |
14416 KB |
Output is correct |
29 |
Correct |
10 ms |
14416 KB |
Output is correct |
30 |
Correct |
21 ms |
15908 KB |
Output is correct |
31 |
Correct |
13 ms |
15100 KB |
Output is correct |
32 |
Correct |
26 ms |
17536 KB |
Output is correct |
33 |
Correct |
25 ms |
16584 KB |
Output is correct |
34 |
Correct |
35 ms |
20216 KB |
Output is correct |
35 |
Correct |
43 ms |
17852 KB |
Output is correct |
36 |
Correct |
39 ms |
16572 KB |
Output is correct |
37 |
Correct |
36 ms |
16572 KB |
Output is correct |
38 |
Correct |
30 ms |
16328 KB |
Output is correct |
39 |
Correct |
32 ms |
16360 KB |
Output is correct |
40 |
Correct |
53 ms |
19972 KB |
Output is correct |
41 |
Correct |
45 ms |
17352 KB |
Output is correct |
42 |
Correct |
38 ms |
16968 KB |
Output is correct |
43 |
Correct |
49 ms |
17596 KB |
Output is correct |
44 |
Correct |
39 ms |
17340 KB |
Output is correct |
45 |
Correct |
248 ms |
29240 KB |
Output is correct |
46 |
Correct |
15 ms |
18388 KB |
Output is correct |
47 |
Correct |
16 ms |
18304 KB |
Output is correct |
48 |
Correct |
329 ms |
46204 KB |
Output is correct |
49 |
Correct |
283 ms |
36684 KB |
Output is correct |
50 |
Correct |
564 ms |
51516 KB |
Output is correct |
51 |
Correct |
773 ms |
45580 KB |
Output is correct |
52 |
Correct |
507 ms |
36548 KB |
Output is correct |
53 |
Correct |
614 ms |
36768 KB |
Output is correct |
54 |
Correct |
700 ms |
36404 KB |
Output is correct |
55 |
Correct |
958 ms |
36960 KB |
Output is correct |
56 |
Correct |
953 ms |
36556 KB |
Output is correct |
57 |
Correct |
419 ms |
30812 KB |
Output is correct |
58 |
Correct |
478 ms |
30644 KB |
Output is correct |
59 |
Correct |
456 ms |
30640 KB |
Output is correct |
60 |
Correct |
395 ms |
30632 KB |
Output is correct |
61 |
Correct |
434 ms |
30204 KB |
Output is correct |
62 |
Correct |
442 ms |
40608 KB |
Output is correct |
63 |
Correct |
419 ms |
37284 KB |
Output is correct |
64 |
Correct |
1059 ms |
64028 KB |
Output is correct |
65 |
Correct |
486 ms |
37356 KB |
Output is correct |
66 |
Correct |
432 ms |
33384 KB |
Output is correct |
67 |
Correct |
747 ms |
42480 KB |
Output is correct |
68 |
Correct |
212 ms |
27380 KB |
Output is correct |
69 |
Correct |
65 ms |
21296 KB |
Output is correct |
70 |
Correct |
673 ms |
41760 KB |
Output is correct |
71 |
Correct |
299 ms |
30188 KB |
Output is correct |
72 |
Correct |
238 ms |
26024 KB |
Output is correct |
73 |
Correct |
610 ms |
39380 KB |
Output is correct |
74 |
Correct |
1032 ms |
36088 KB |
Output is correct |
75 |
Correct |
1018 ms |
46292 KB |
Output is correct |
76 |
Correct |
886 ms |
45364 KB |
Output is correct |