#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];
int l[300001],r[300001];
//leftmost special guy node i can reach
//rightmost special guy who can reach node i
//cycle iff exists l[i]<=r[i]
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);
}
l[i]=i;
r[i]=i;
}
for (int i=k+1;i<=n;i++){
l[i]=n+1;
r[i]=0;
}
}
bool vis[300001];
void dfs0(int x,int val){
if (vis[x]) return;
vis[x]=true;
l[x]=min(l[x],val);
for (auto i:rev[x]) dfs0(i,val);
}
void dfs1(int x,int val){
if (vis[x]) return;
vis[x]=true;
r[x]=max(r[x],val);
for (auto i:adj[x]) dfs1(i,val);
}
int add_teleporter(int u,int v){
u++;
v++;
adj[u].pb(v);
rev[v].pb(u);
if (max(u,v)<=k){
if (u>=v) return 1;
}
if (l[u]>l[v]){
for (int i=1;i<=n;i++) vis[i]=false;
dfs0(u,l[v]);
for (int i=1;i<=k;i++){
if (l[i]<r[i]) return 1;
}
for (int i=k+1;i<=n;i++){
if (l[i]<=r[i]) return 1;
}
}
if (r[u]>r[v]){
for (int i=1;i<=n;i++) vis[i]=false;
dfs1(v,r[u]);
for (int i=1;i<=k;i++){
if (l[i]<r[i]) return 1;
}
for (int i=k+1;i<=n;i++){
if (l[i]<=r[i]) return 1;
}
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
14468 KB |
Output is correct |
2 |
Correct |
9 ms |
14288 KB |
Output is correct |
3 |
Correct |
10 ms |
14416 KB |
Output is correct |
4 |
Correct |
8 ms |
14292 KB |
Output is correct |
5 |
Correct |
7 ms |
14416 KB |
Output is correct |
6 |
Correct |
7 ms |
14416 KB |
Output is correct |
7 |
Correct |
8 ms |
14320 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
14468 KB |
Output is correct |
2 |
Correct |
9 ms |
14288 KB |
Output is correct |
3 |
Correct |
10 ms |
14416 KB |
Output is correct |
4 |
Correct |
8 ms |
14292 KB |
Output is correct |
5 |
Correct |
7 ms |
14416 KB |
Output is correct |
6 |
Correct |
7 ms |
14416 KB |
Output is correct |
7 |
Correct |
8 ms |
14320 KB |
Output is correct |
8 |
Correct |
7 ms |
14288 KB |
Output is correct |
9 |
Correct |
7 ms |
14288 KB |
Output is correct |
10 |
Correct |
7 ms |
14288 KB |
Output is correct |
11 |
Correct |
8 ms |
14416 KB |
Output is correct |
12 |
Correct |
7 ms |
14416 KB |
Output is correct |
13 |
Correct |
10 ms |
14408 KB |
Output is correct |
14 |
Correct |
9 ms |
14288 KB |
Output is correct |
15 |
Correct |
9 ms |
14416 KB |
Output is correct |
16 |
Correct |
9 ms |
14416 KB |
Output is correct |
17 |
Correct |
9 ms |
14292 KB |
Output is correct |
18 |
Correct |
8 ms |
14340 KB |
Output is correct |
19 |
Correct |
8 ms |
14416 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
14468 KB |
Output is correct |
2 |
Correct |
9 ms |
14288 KB |
Output is correct |
3 |
Correct |
10 ms |
14416 KB |
Output is correct |
4 |
Correct |
8 ms |
14292 KB |
Output is correct |
5 |
Correct |
7 ms |
14416 KB |
Output is correct |
6 |
Correct |
7 ms |
14416 KB |
Output is correct |
7 |
Correct |
8 ms |
14320 KB |
Output is correct |
8 |
Correct |
7 ms |
14288 KB |
Output is correct |
9 |
Correct |
7 ms |
14288 KB |
Output is correct |
10 |
Correct |
7 ms |
14288 KB |
Output is correct |
11 |
Correct |
8 ms |
14416 KB |
Output is correct |
12 |
Correct |
7 ms |
14416 KB |
Output is correct |
13 |
Correct |
10 ms |
14408 KB |
Output is correct |
14 |
Correct |
9 ms |
14288 KB |
Output is correct |
15 |
Correct |
9 ms |
14416 KB |
Output is correct |
16 |
Correct |
9 ms |
14416 KB |
Output is correct |
17 |
Correct |
9 ms |
14292 KB |
Output is correct |
18 |
Correct |
8 ms |
14340 KB |
Output is correct |
19 |
Correct |
8 ms |
14416 KB |
Output is correct |
20 |
Correct |
8 ms |
14416 KB |
Output is correct |
21 |
Correct |
8 ms |
14416 KB |
Output is correct |
22 |
Correct |
10 ms |
14416 KB |
Output is correct |
23 |
Correct |
9 ms |
14468 KB |
Output is correct |
24 |
Correct |
12 ms |
14416 KB |
Output is correct |
25 |
Correct |
11 ms |
14416 KB |
Output is correct |
26 |
Correct |
14 ms |
14548 KB |
Output is correct |
27 |
Correct |
12 ms |
14512 KB |
Output is correct |
28 |
Correct |
10 ms |
14416 KB |
Output is correct |
29 |
Correct |
13 ms |
14512 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
14468 KB |
Output is correct |
2 |
Correct |
9 ms |
14288 KB |
Output is correct |
3 |
Correct |
10 ms |
14416 KB |
Output is correct |
4 |
Correct |
8 ms |
14292 KB |
Output is correct |
5 |
Correct |
7 ms |
14416 KB |
Output is correct |
6 |
Correct |
7 ms |
14416 KB |
Output is correct |
7 |
Correct |
8 ms |
14320 KB |
Output is correct |
8 |
Correct |
7 ms |
14288 KB |
Output is correct |
9 |
Correct |
7 ms |
14288 KB |
Output is correct |
10 |
Correct |
7 ms |
14288 KB |
Output is correct |
11 |
Correct |
8 ms |
14416 KB |
Output is correct |
12 |
Correct |
7 ms |
14416 KB |
Output is correct |
13 |
Correct |
10 ms |
14408 KB |
Output is correct |
14 |
Correct |
9 ms |
14288 KB |
Output is correct |
15 |
Correct |
9 ms |
14416 KB |
Output is correct |
16 |
Correct |
9 ms |
14416 KB |
Output is correct |
17 |
Correct |
9 ms |
14292 KB |
Output is correct |
18 |
Correct |
8 ms |
14340 KB |
Output is correct |
19 |
Correct |
8 ms |
14416 KB |
Output is correct |
20 |
Correct |
8 ms |
14416 KB |
Output is correct |
21 |
Correct |
8 ms |
14416 KB |
Output is correct |
22 |
Correct |
10 ms |
14416 KB |
Output is correct |
23 |
Correct |
9 ms |
14468 KB |
Output is correct |
24 |
Correct |
12 ms |
14416 KB |
Output is correct |
25 |
Correct |
11 ms |
14416 KB |
Output is correct |
26 |
Correct |
14 ms |
14548 KB |
Output is correct |
27 |
Correct |
12 ms |
14512 KB |
Output is correct |
28 |
Correct |
10 ms |
14416 KB |
Output is correct |
29 |
Correct |
13 ms |
14512 KB |
Output is correct |
30 |
Correct |
36 ms |
15688 KB |
Output is correct |
31 |
Correct |
22 ms |
15028 KB |
Output is correct |
32 |
Correct |
29 ms |
16996 KB |
Output is correct |
33 |
Correct |
27 ms |
16456 KB |
Output is correct |
34 |
Correct |
1116 ms |
17436 KB |
Output is correct |
35 |
Correct |
1014 ms |
17284 KB |
Output is correct |
36 |
Correct |
971 ms |
16616 KB |
Output is correct |
37 |
Correct |
1034 ms |
16568 KB |
Output is correct |
38 |
Correct |
1022 ms |
16332 KB |
Output is correct |
39 |
Correct |
973 ms |
16568 KB |
Output is correct |
40 |
Correct |
1036 ms |
17632 KB |
Output is correct |
41 |
Correct |
720 ms |
16808 KB |
Output is correct |
42 |
Correct |
453 ms |
16544 KB |
Output is correct |
43 |
Correct |
1768 ms |
17688 KB |
Output is correct |
44 |
Correct |
1200 ms |
17660 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
14468 KB |
Output is correct |
2 |
Correct |
9 ms |
14288 KB |
Output is correct |
3 |
Correct |
10 ms |
14416 KB |
Output is correct |
4 |
Correct |
8 ms |
14292 KB |
Output is correct |
5 |
Correct |
7 ms |
14416 KB |
Output is correct |
6 |
Correct |
7 ms |
14416 KB |
Output is correct |
7 |
Correct |
8 ms |
14320 KB |
Output is correct |
8 |
Correct |
7 ms |
14288 KB |
Output is correct |
9 |
Correct |
7 ms |
14288 KB |
Output is correct |
10 |
Correct |
7 ms |
14288 KB |
Output is correct |
11 |
Correct |
8 ms |
14416 KB |
Output is correct |
12 |
Correct |
7 ms |
14416 KB |
Output is correct |
13 |
Correct |
10 ms |
14408 KB |
Output is correct |
14 |
Correct |
9 ms |
14288 KB |
Output is correct |
15 |
Correct |
9 ms |
14416 KB |
Output is correct |
16 |
Correct |
9 ms |
14416 KB |
Output is correct |
17 |
Correct |
9 ms |
14292 KB |
Output is correct |
18 |
Correct |
8 ms |
14340 KB |
Output is correct |
19 |
Correct |
8 ms |
14416 KB |
Output is correct |
20 |
Correct |
8 ms |
14416 KB |
Output is correct |
21 |
Correct |
8 ms |
14416 KB |
Output is correct |
22 |
Correct |
10 ms |
14416 KB |
Output is correct |
23 |
Correct |
9 ms |
14468 KB |
Output is correct |
24 |
Correct |
12 ms |
14416 KB |
Output is correct |
25 |
Correct |
11 ms |
14416 KB |
Output is correct |
26 |
Correct |
14 ms |
14548 KB |
Output is correct |
27 |
Correct |
12 ms |
14512 KB |
Output is correct |
28 |
Correct |
10 ms |
14416 KB |
Output is correct |
29 |
Correct |
13 ms |
14512 KB |
Output is correct |
30 |
Correct |
36 ms |
15688 KB |
Output is correct |
31 |
Correct |
22 ms |
15028 KB |
Output is correct |
32 |
Correct |
29 ms |
16996 KB |
Output is correct |
33 |
Correct |
27 ms |
16456 KB |
Output is correct |
34 |
Correct |
1116 ms |
17436 KB |
Output is correct |
35 |
Correct |
1014 ms |
17284 KB |
Output is correct |
36 |
Correct |
971 ms |
16616 KB |
Output is correct |
37 |
Correct |
1034 ms |
16568 KB |
Output is correct |
38 |
Correct |
1022 ms |
16332 KB |
Output is correct |
39 |
Correct |
973 ms |
16568 KB |
Output is correct |
40 |
Correct |
1036 ms |
17632 KB |
Output is correct |
41 |
Correct |
720 ms |
16808 KB |
Output is correct |
42 |
Correct |
453 ms |
16544 KB |
Output is correct |
43 |
Correct |
1768 ms |
17688 KB |
Output is correct |
44 |
Correct |
1200 ms |
17660 KB |
Output is correct |
45 |
Correct |
324 ms |
28276 KB |
Output is correct |
46 |
Correct |
21 ms |
17488 KB |
Output is correct |
47 |
Correct |
30 ms |
17476 KB |
Output is correct |
48 |
Correct |
355 ms |
40540 KB |
Output is correct |
49 |
Correct |
346 ms |
35848 KB |
Output is correct |
50 |
Execution timed out |
4094 ms |
40368 KB |
Time limit exceeded |
51 |
Halted |
0 ms |
0 KB |
- |