#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
using namespace __gnu_pbds;
using namespace std;
#define pb push_back
#define st first
#define nd second
typedef long long ll;
typedef long double ld;
const ll I = 1000LL * 1000LL * 1000LL * 1000LL * 1000LL * 1000LL;
const int II = 2 * 1000 * 1000 * 1000;
const ll M = 1000LL * 1000LL * 1000LL + 7LL;
const int N = 1000 * 1000 + 7;
int n, q;
vector<int> ed[N], red[N];
int p[N], k[N], cnt[N];
bool answer;
bool Chk(int a, int b, int r)
{
if(r == 0) return false;
return !(((1<<r) & a) ^ ((1<<r) & b));
}
void Upd(int v)
{
if(p[v] > k[v] || (v >= q && p[v] >= k[v])) answer = true;
//cerr << "U: " << v << " " << p[v] << " " << k[v] << " " << answer << "\n";
if(answer) return;
if(!Chk(p[v], k[v], cnt[v])) return;
while(Chk(p[v], k[v], cnt[v])) --cnt[v];
for(int i = 0; i < (int)ed[v].size(); ++i)
if(p[ed[v][i]] < p[v])
{
p[ed[v][i]] = p[v];
Upd(ed[v][i]);
}
for(int i = 0; i < (int)red[v].size(); ++i)
if(k[red[v][i]] > k[v])
{
k[red[v][i]] = k[v];
Upd(red[v][i]);
}
}
void init(int _n, int _k)
{
n = _n; q = _k;
for(int i = 0; i < q; ++i)
{
p[i] = i + 1; k[i] = i + 1;
}
for(int i = q; i < n; ++i)
{
p[i] = 0;
k[i] = q + 1;
cnt[i] = 20;
}
for(int i = 0; i < n; ++i)
while(Chk(p[i], k[i], cnt[i]))
--cnt[i];
}
int add_teleporter(int u, int v)
{
if(u == v && v < q) return 1;
//cerr << "EDGE: " << u << " " << v << "\n";
ed[u].pb(v); red[v].pb(u);
if(p[v] < p[u])
{
p[v] = p[u];
Upd(v);
}
if(k[u] > k[v])
{
k[u] = k[v];
Upd(u);
}
if(answer)
return 1;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
48472 KB |
Output is correct |
2 |
Correct |
15 ms |
48536 KB |
Output is correct |
3 |
Correct |
15 ms |
48724 KB |
Output is correct |
4 |
Correct |
13 ms |
48728 KB |
Output is correct |
5 |
Correct |
15 ms |
48608 KB |
Output is correct |
6 |
Correct |
16 ms |
48728 KB |
Output is correct |
7 |
Correct |
14 ms |
48728 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
48472 KB |
Output is correct |
2 |
Correct |
15 ms |
48536 KB |
Output is correct |
3 |
Correct |
15 ms |
48724 KB |
Output is correct |
4 |
Correct |
13 ms |
48728 KB |
Output is correct |
5 |
Correct |
15 ms |
48608 KB |
Output is correct |
6 |
Correct |
16 ms |
48728 KB |
Output is correct |
7 |
Correct |
14 ms |
48728 KB |
Output is correct |
8 |
Correct |
14 ms |
48472 KB |
Output is correct |
9 |
Correct |
14 ms |
48576 KB |
Output is correct |
10 |
Correct |
15 ms |
48552 KB |
Output is correct |
11 |
Correct |
14 ms |
48728 KB |
Output is correct |
12 |
Correct |
16 ms |
47192 KB |
Output is correct |
13 |
Correct |
16 ms |
47296 KB |
Output is correct |
14 |
Correct |
15 ms |
48592 KB |
Output is correct |
15 |
Correct |
14 ms |
48728 KB |
Output is correct |
16 |
Correct |
16 ms |
47320 KB |
Output is correct |
17 |
Correct |
14 ms |
47192 KB |
Output is correct |
18 |
Correct |
14 ms |
48728 KB |
Output is correct |
19 |
Correct |
18 ms |
47192 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
48472 KB |
Output is correct |
2 |
Correct |
15 ms |
48536 KB |
Output is correct |
3 |
Correct |
15 ms |
48724 KB |
Output is correct |
4 |
Correct |
13 ms |
48728 KB |
Output is correct |
5 |
Correct |
15 ms |
48608 KB |
Output is correct |
6 |
Correct |
16 ms |
48728 KB |
Output is correct |
7 |
Correct |
14 ms |
48728 KB |
Output is correct |
8 |
Correct |
14 ms |
48472 KB |
Output is correct |
9 |
Correct |
14 ms |
48576 KB |
Output is correct |
10 |
Correct |
15 ms |
48552 KB |
Output is correct |
11 |
Correct |
14 ms |
48728 KB |
Output is correct |
12 |
Correct |
16 ms |
47192 KB |
Output is correct |
13 |
Correct |
16 ms |
47296 KB |
Output is correct |
14 |
Correct |
15 ms |
48592 KB |
Output is correct |
15 |
Correct |
14 ms |
48728 KB |
Output is correct |
16 |
Correct |
16 ms |
47320 KB |
Output is correct |
17 |
Correct |
14 ms |
47192 KB |
Output is correct |
18 |
Correct |
14 ms |
48728 KB |
Output is correct |
19 |
Correct |
18 ms |
47192 KB |
Output is correct |
20 |
Correct |
16 ms |
48728 KB |
Output is correct |
21 |
Correct |
16 ms |
48728 KB |
Output is correct |
22 |
Correct |
16 ms |
48728 KB |
Output is correct |
23 |
Correct |
13 ms |
48728 KB |
Output is correct |
24 |
Correct |
13 ms |
48728 KB |
Output is correct |
25 |
Correct |
16 ms |
47448 KB |
Output is correct |
26 |
Correct |
18 ms |
48728 KB |
Output is correct |
27 |
Correct |
16 ms |
48728 KB |
Output is correct |
28 |
Correct |
17 ms |
47472 KB |
Output is correct |
29 |
Correct |
19 ms |
47448 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
48472 KB |
Output is correct |
2 |
Correct |
15 ms |
48536 KB |
Output is correct |
3 |
Correct |
15 ms |
48724 KB |
Output is correct |
4 |
Correct |
13 ms |
48728 KB |
Output is correct |
5 |
Correct |
15 ms |
48608 KB |
Output is correct |
6 |
Correct |
16 ms |
48728 KB |
Output is correct |
7 |
Correct |
14 ms |
48728 KB |
Output is correct |
8 |
Correct |
14 ms |
48472 KB |
Output is correct |
9 |
Correct |
14 ms |
48576 KB |
Output is correct |
10 |
Correct |
15 ms |
48552 KB |
Output is correct |
11 |
Correct |
14 ms |
48728 KB |
Output is correct |
12 |
Correct |
16 ms |
47192 KB |
Output is correct |
13 |
Correct |
16 ms |
47296 KB |
Output is correct |
14 |
Correct |
15 ms |
48592 KB |
Output is correct |
15 |
Correct |
14 ms |
48728 KB |
Output is correct |
16 |
Correct |
16 ms |
47320 KB |
Output is correct |
17 |
Correct |
14 ms |
47192 KB |
Output is correct |
18 |
Correct |
14 ms |
48728 KB |
Output is correct |
19 |
Correct |
18 ms |
47192 KB |
Output is correct |
20 |
Correct |
16 ms |
48728 KB |
Output is correct |
21 |
Correct |
16 ms |
48728 KB |
Output is correct |
22 |
Correct |
16 ms |
48728 KB |
Output is correct |
23 |
Correct |
13 ms |
48728 KB |
Output is correct |
24 |
Correct |
13 ms |
48728 KB |
Output is correct |
25 |
Correct |
16 ms |
47448 KB |
Output is correct |
26 |
Correct |
18 ms |
48728 KB |
Output is correct |
27 |
Correct |
16 ms |
48728 KB |
Output is correct |
28 |
Correct |
17 ms |
47472 KB |
Output is correct |
29 |
Correct |
19 ms |
47448 KB |
Output is correct |
30 |
Correct |
27 ms |
48728 KB |
Output is correct |
31 |
Correct |
20 ms |
48096 KB |
Output is correct |
32 |
Correct |
28 ms |
51856 KB |
Output is correct |
33 |
Correct |
26 ms |
50776 KB |
Output is correct |
34 |
Correct |
34 ms |
54352 KB |
Output is correct |
35 |
Correct |
33 ms |
52056 KB |
Output is correct |
36 |
Correct |
31 ms |
50948 KB |
Output is correct |
37 |
Correct |
28 ms |
50776 KB |
Output is correct |
38 |
Correct |
30 ms |
50468 KB |
Output is correct |
39 |
Correct |
31 ms |
50520 KB |
Output is correct |
40 |
Correct |
44 ms |
54236 KB |
Output is correct |
41 |
Correct |
36 ms |
51536 KB |
Output is correct |
42 |
Correct |
36 ms |
50000 KB |
Output is correct |
43 |
Correct |
51 ms |
50736 KB |
Output is correct |
44 |
Correct |
40 ms |
51544 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
48472 KB |
Output is correct |
2 |
Correct |
15 ms |
48536 KB |
Output is correct |
3 |
Correct |
15 ms |
48724 KB |
Output is correct |
4 |
Correct |
13 ms |
48728 KB |
Output is correct |
5 |
Correct |
15 ms |
48608 KB |
Output is correct |
6 |
Correct |
16 ms |
48728 KB |
Output is correct |
7 |
Correct |
14 ms |
48728 KB |
Output is correct |
8 |
Correct |
14 ms |
48472 KB |
Output is correct |
9 |
Correct |
14 ms |
48576 KB |
Output is correct |
10 |
Correct |
15 ms |
48552 KB |
Output is correct |
11 |
Correct |
14 ms |
48728 KB |
Output is correct |
12 |
Correct |
16 ms |
47192 KB |
Output is correct |
13 |
Correct |
16 ms |
47296 KB |
Output is correct |
14 |
Correct |
15 ms |
48592 KB |
Output is correct |
15 |
Correct |
14 ms |
48728 KB |
Output is correct |
16 |
Correct |
16 ms |
47320 KB |
Output is correct |
17 |
Correct |
14 ms |
47192 KB |
Output is correct |
18 |
Correct |
14 ms |
48728 KB |
Output is correct |
19 |
Correct |
18 ms |
47192 KB |
Output is correct |
20 |
Correct |
16 ms |
48728 KB |
Output is correct |
21 |
Correct |
16 ms |
48728 KB |
Output is correct |
22 |
Correct |
16 ms |
48728 KB |
Output is correct |
23 |
Correct |
13 ms |
48728 KB |
Output is correct |
24 |
Correct |
13 ms |
48728 KB |
Output is correct |
25 |
Correct |
16 ms |
47448 KB |
Output is correct |
26 |
Correct |
18 ms |
48728 KB |
Output is correct |
27 |
Correct |
16 ms |
48728 KB |
Output is correct |
28 |
Correct |
17 ms |
47472 KB |
Output is correct |
29 |
Correct |
19 ms |
47448 KB |
Output is correct |
30 |
Correct |
27 ms |
48728 KB |
Output is correct |
31 |
Correct |
20 ms |
48096 KB |
Output is correct |
32 |
Correct |
28 ms |
51856 KB |
Output is correct |
33 |
Correct |
26 ms |
50776 KB |
Output is correct |
34 |
Correct |
34 ms |
54352 KB |
Output is correct |
35 |
Correct |
33 ms |
52056 KB |
Output is correct |
36 |
Correct |
31 ms |
50948 KB |
Output is correct |
37 |
Correct |
28 ms |
50776 KB |
Output is correct |
38 |
Correct |
30 ms |
50468 KB |
Output is correct |
39 |
Correct |
31 ms |
50520 KB |
Output is correct |
40 |
Correct |
44 ms |
54236 KB |
Output is correct |
41 |
Correct |
36 ms |
51536 KB |
Output is correct |
42 |
Correct |
36 ms |
50000 KB |
Output is correct |
43 |
Correct |
51 ms |
50736 KB |
Output is correct |
44 |
Correct |
40 ms |
51544 KB |
Output is correct |
45 |
Correct |
163 ms |
63552 KB |
Output is correct |
46 |
Correct |
23 ms |
51372 KB |
Output is correct |
47 |
Correct |
22 ms |
51144 KB |
Output is correct |
48 |
Correct |
217 ms |
80708 KB |
Output is correct |
49 |
Correct |
154 ms |
71096 KB |
Output is correct |
50 |
Correct |
309 ms |
85052 KB |
Output is correct |
51 |
Correct |
432 ms |
79564 KB |
Output is correct |
52 |
Correct |
308 ms |
70856 KB |
Output is correct |
53 |
Correct |
444 ms |
71080 KB |
Output is correct |
54 |
Correct |
380 ms |
70876 KB |
Output is correct |
55 |
Correct |
537 ms |
71244 KB |
Output is correct |
56 |
Correct |
533 ms |
70952 KB |
Output is correct |
57 |
Correct |
236 ms |
64356 KB |
Output is correct |
58 |
Correct |
285 ms |
64676 KB |
Output is correct |
59 |
Correct |
246 ms |
64796 KB |
Output is correct |
60 |
Correct |
222 ms |
64236 KB |
Output is correct |
61 |
Correct |
236 ms |
64024 KB |
Output is correct |
62 |
Correct |
201 ms |
74616 KB |
Output is correct |
63 |
Correct |
200 ms |
71332 KB |
Output is correct |
64 |
Correct |
545 ms |
97832 KB |
Output is correct |
65 |
Correct |
243 ms |
71408 KB |
Output is correct |
66 |
Correct |
194 ms |
66244 KB |
Output is correct |
67 |
Correct |
338 ms |
75244 KB |
Output is correct |
68 |
Correct |
143 ms |
61520 KB |
Output is correct |
69 |
Correct |
42 ms |
55328 KB |
Output is correct |
70 |
Correct |
380 ms |
75508 KB |
Output is correct |
71 |
Correct |
192 ms |
64216 KB |
Output is correct |
72 |
Correct |
148 ms |
60400 KB |
Output is correct |
73 |
Correct |
314 ms |
73536 KB |
Output is correct |
74 |
Correct |
556 ms |
70504 KB |
Output is correct |
75 |
Correct |
589 ms |
80708 KB |
Output is correct |
76 |
Correct |
599 ms |
79652 KB |
Output is correct |