#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
const int MOD=1e9+7;
int n,k;
vector<int> adj[300001],rev[300001];
pair<int,int> range[300001];
//rightmost special node to go i, leftmost special node i can go to
void init(int N,int K){
n=N;
k=K;
for (int i=1;i<=k;i++){
if (i<k){
adj[i].pb(i+1);
rev[i+1].pb(i);
}
range[i]=mp(i,i);
}
for (int i=k+1;i<=n;i++){
range[i]=mp(0,k+1);
}
}
bool upd(int u,int v){
if (range[u].second<=range[v].first) return false;
if (range[u].first>=range[v].second) return true;
while ((range[v].first+range[v].second)/2<range[u].first){
range[v].first=(range[v].first+range[v].second)/2+1;
for (auto i:adj[v]){
if (upd(v,i)) return true;
}
}
while ((range[u].second+range[u].first)/2>=range[v].second){
range[u].second=(range[u].second+range[u].first)/2;
for (auto i:rev[u]){
if (upd(i,u)) return true;
}
}
return false;
}
int add_teleporter(int u,int v){
u++;
v++;
if (u>=v && u<=k) return 1;
if (u==v) return 0;
adj[u].pb(v);
rev[v].pb(u);
return upd(u,v);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
14288 KB |
Output is correct |
2 |
Correct |
8 ms |
14296 KB |
Output is correct |
3 |
Correct |
8 ms |
14364 KB |
Output is correct |
4 |
Correct |
8 ms |
14288 KB |
Output is correct |
5 |
Correct |
8 ms |
14288 KB |
Output is correct |
6 |
Correct |
8 ms |
14320 KB |
Output is correct |
7 |
Correct |
9 ms |
14364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
14288 KB |
Output is correct |
2 |
Correct |
8 ms |
14296 KB |
Output is correct |
3 |
Correct |
8 ms |
14364 KB |
Output is correct |
4 |
Correct |
8 ms |
14288 KB |
Output is correct |
5 |
Correct |
8 ms |
14288 KB |
Output is correct |
6 |
Correct |
8 ms |
14320 KB |
Output is correct |
7 |
Correct |
9 ms |
14364 KB |
Output is correct |
8 |
Correct |
8 ms |
14288 KB |
Output is correct |
9 |
Correct |
9 ms |
14372 KB |
Output is correct |
10 |
Correct |
8 ms |
14288 KB |
Output is correct |
11 |
Correct |
9 ms |
14284 KB |
Output is correct |
12 |
Correct |
8 ms |
14288 KB |
Output is correct |
13 |
Correct |
8 ms |
14404 KB |
Output is correct |
14 |
Correct |
8 ms |
14404 KB |
Output is correct |
15 |
Correct |
8 ms |
14288 KB |
Output is correct |
16 |
Correct |
8 ms |
14452 KB |
Output is correct |
17 |
Correct |
8 ms |
14288 KB |
Output is correct |
18 |
Correct |
8 ms |
14476 KB |
Output is correct |
19 |
Correct |
8 ms |
14288 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
14288 KB |
Output is correct |
2 |
Correct |
8 ms |
14296 KB |
Output is correct |
3 |
Correct |
8 ms |
14364 KB |
Output is correct |
4 |
Correct |
8 ms |
14288 KB |
Output is correct |
5 |
Correct |
8 ms |
14288 KB |
Output is correct |
6 |
Correct |
8 ms |
14320 KB |
Output is correct |
7 |
Correct |
9 ms |
14364 KB |
Output is correct |
8 |
Correct |
8 ms |
14288 KB |
Output is correct |
9 |
Correct |
9 ms |
14372 KB |
Output is correct |
10 |
Correct |
8 ms |
14288 KB |
Output is correct |
11 |
Correct |
9 ms |
14284 KB |
Output is correct |
12 |
Correct |
8 ms |
14288 KB |
Output is correct |
13 |
Correct |
8 ms |
14404 KB |
Output is correct |
14 |
Correct |
8 ms |
14404 KB |
Output is correct |
15 |
Correct |
8 ms |
14288 KB |
Output is correct |
16 |
Correct |
8 ms |
14452 KB |
Output is correct |
17 |
Correct |
8 ms |
14288 KB |
Output is correct |
18 |
Correct |
8 ms |
14476 KB |
Output is correct |
19 |
Correct |
8 ms |
14288 KB |
Output is correct |
20 |
Correct |
9 ms |
14416 KB |
Output is correct |
21 |
Correct |
8 ms |
14288 KB |
Output is correct |
22 |
Correct |
8 ms |
14416 KB |
Output is correct |
23 |
Correct |
8 ms |
14408 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 |
14484 KB |
Output is correct |
27 |
Correct |
9 ms |
14416 KB |
Output is correct |
28 |
Correct |
10 ms |
14544 KB |
Output is correct |
29 |
Correct |
10 ms |
14564 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
14288 KB |
Output is correct |
2 |
Correct |
8 ms |
14296 KB |
Output is correct |
3 |
Correct |
8 ms |
14364 KB |
Output is correct |
4 |
Correct |
8 ms |
14288 KB |
Output is correct |
5 |
Correct |
8 ms |
14288 KB |
Output is correct |
6 |
Correct |
8 ms |
14320 KB |
Output is correct |
7 |
Correct |
9 ms |
14364 KB |
Output is correct |
8 |
Correct |
8 ms |
14288 KB |
Output is correct |
9 |
Correct |
9 ms |
14372 KB |
Output is correct |
10 |
Correct |
8 ms |
14288 KB |
Output is correct |
11 |
Correct |
9 ms |
14284 KB |
Output is correct |
12 |
Correct |
8 ms |
14288 KB |
Output is correct |
13 |
Correct |
8 ms |
14404 KB |
Output is correct |
14 |
Correct |
8 ms |
14404 KB |
Output is correct |
15 |
Correct |
8 ms |
14288 KB |
Output is correct |
16 |
Correct |
8 ms |
14452 KB |
Output is correct |
17 |
Correct |
8 ms |
14288 KB |
Output is correct |
18 |
Correct |
8 ms |
14476 KB |
Output is correct |
19 |
Correct |
8 ms |
14288 KB |
Output is correct |
20 |
Correct |
9 ms |
14416 KB |
Output is correct |
21 |
Correct |
8 ms |
14288 KB |
Output is correct |
22 |
Correct |
8 ms |
14416 KB |
Output is correct |
23 |
Correct |
8 ms |
14408 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 |
14484 KB |
Output is correct |
27 |
Correct |
9 ms |
14416 KB |
Output is correct |
28 |
Correct |
10 ms |
14544 KB |
Output is correct |
29 |
Correct |
10 ms |
14564 KB |
Output is correct |
30 |
Correct |
22 ms |
15780 KB |
Output is correct |
31 |
Correct |
13 ms |
15056 KB |
Output is correct |
32 |
Correct |
33 ms |
18768 KB |
Output is correct |
33 |
Correct |
27 ms |
16436 KB |
Output is correct |
34 |
Correct |
49 ms |
21040 KB |
Output is correct |
35 |
Correct |
46 ms |
18060 KB |
Output is correct |
36 |
Correct |
43 ms |
16452 KB |
Output is correct |
37 |
Correct |
45 ms |
16480 KB |
Output is correct |
38 |
Correct |
52 ms |
16264 KB |
Output is correct |
39 |
Correct |
36 ms |
16296 KB |
Output is correct |
40 |
Correct |
48 ms |
20732 KB |
Output is correct |
41 |
Correct |
41 ms |
17420 KB |
Output is correct |
42 |
Correct |
52 ms |
17036 KB |
Output is correct |
43 |
Correct |
59 ms |
17736 KB |
Output is correct |
44 |
Correct |
48 ms |
17596 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
14288 KB |
Output is correct |
2 |
Correct |
8 ms |
14296 KB |
Output is correct |
3 |
Correct |
8 ms |
14364 KB |
Output is correct |
4 |
Correct |
8 ms |
14288 KB |
Output is correct |
5 |
Correct |
8 ms |
14288 KB |
Output is correct |
6 |
Correct |
8 ms |
14320 KB |
Output is correct |
7 |
Correct |
9 ms |
14364 KB |
Output is correct |
8 |
Correct |
8 ms |
14288 KB |
Output is correct |
9 |
Correct |
9 ms |
14372 KB |
Output is correct |
10 |
Correct |
8 ms |
14288 KB |
Output is correct |
11 |
Correct |
9 ms |
14284 KB |
Output is correct |
12 |
Correct |
8 ms |
14288 KB |
Output is correct |
13 |
Correct |
8 ms |
14404 KB |
Output is correct |
14 |
Correct |
8 ms |
14404 KB |
Output is correct |
15 |
Correct |
8 ms |
14288 KB |
Output is correct |
16 |
Correct |
8 ms |
14452 KB |
Output is correct |
17 |
Correct |
8 ms |
14288 KB |
Output is correct |
18 |
Correct |
8 ms |
14476 KB |
Output is correct |
19 |
Correct |
8 ms |
14288 KB |
Output is correct |
20 |
Correct |
9 ms |
14416 KB |
Output is correct |
21 |
Correct |
8 ms |
14288 KB |
Output is correct |
22 |
Correct |
8 ms |
14416 KB |
Output is correct |
23 |
Correct |
8 ms |
14408 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 |
14484 KB |
Output is correct |
27 |
Correct |
9 ms |
14416 KB |
Output is correct |
28 |
Correct |
10 ms |
14544 KB |
Output is correct |
29 |
Correct |
10 ms |
14564 KB |
Output is correct |
30 |
Correct |
22 ms |
15780 KB |
Output is correct |
31 |
Correct |
13 ms |
15056 KB |
Output is correct |
32 |
Correct |
33 ms |
18768 KB |
Output is correct |
33 |
Correct |
27 ms |
16436 KB |
Output is correct |
34 |
Correct |
49 ms |
21040 KB |
Output is correct |
35 |
Correct |
46 ms |
18060 KB |
Output is correct |
36 |
Correct |
43 ms |
16452 KB |
Output is correct |
37 |
Correct |
45 ms |
16480 KB |
Output is correct |
38 |
Correct |
52 ms |
16264 KB |
Output is correct |
39 |
Correct |
36 ms |
16296 KB |
Output is correct |
40 |
Correct |
48 ms |
20732 KB |
Output is correct |
41 |
Correct |
41 ms |
17420 KB |
Output is correct |
42 |
Correct |
52 ms |
17036 KB |
Output is correct |
43 |
Correct |
59 ms |
17736 KB |
Output is correct |
44 |
Correct |
48 ms |
17596 KB |
Output is correct |
45 |
Correct |
264 ms |
28000 KB |
Output is correct |
46 |
Correct |
20 ms |
17196 KB |
Output is correct |
47 |
Correct |
16 ms |
17232 KB |
Output is correct |
48 |
Correct |
345 ms |
45484 KB |
Output is correct |
49 |
Correct |
314 ms |
35460 KB |
Output is correct |
50 |
Correct |
654 ms |
59628 KB |
Output is correct |
51 |
Correct |
878 ms |
47912 KB |
Output is correct |
52 |
Correct |
631 ms |
35548 KB |
Output is correct |
53 |
Correct |
847 ms |
35724 KB |
Output is correct |
54 |
Correct |
833 ms |
35800 KB |
Output is correct |
55 |
Correct |
1016 ms |
35772 KB |
Output is correct |
56 |
Correct |
1217 ms |
35904 KB |
Output is correct |
57 |
Correct |
555 ms |
35712 KB |
Output is correct |
58 |
Correct |
522 ms |
35912 KB |
Output is correct |
59 |
Correct |
588 ms |
36076 KB |
Output is correct |
60 |
Correct |
588 ms |
36168 KB |
Output is correct |
61 |
Correct |
635 ms |
36176 KB |
Output is correct |
62 |
Correct |
513 ms |
44296 KB |
Output is correct |
63 |
Correct |
398 ms |
40916 KB |
Output is correct |
64 |
Correct |
1216 ms |
71412 KB |
Output is correct |
65 |
Correct |
539 ms |
38004 KB |
Output is correct |
66 |
Correct |
467 ms |
33964 KB |
Output is correct |
67 |
Correct |
891 ms |
43620 KB |
Output is correct |
68 |
Correct |
203 ms |
29544 KB |
Output is correct |
69 |
Correct |
61 ms |
23372 KB |
Output is correct |
70 |
Correct |
836 ms |
46544 KB |
Output is correct |
71 |
Correct |
358 ms |
30272 KB |
Output is correct |
72 |
Correct |
256 ms |
26152 KB |
Output is correct |
73 |
Correct |
733 ms |
40868 KB |
Output is correct |
74 |
Correct |
1373 ms |
36360 KB |
Output is correct |
75 |
Correct |
1173 ms |
47912 KB |
Output is correct |
76 |
Correct |
1281 ms |
55220 KB |
Output is correct |