#include "circuit.h"
#include <bits/stdc++.h>
using namespace std;
const long long mod=1e9+2022;
long long seg[800005], sum[800005], lazy[400005], state[200005], dp[200005], a[200005], n, m;
vector<long long> adj[200005];
void dfs(long long u)
{
if (u>=n)
{
dp[u]=1;
return;
}
dp[u]=adj[u].size();
for (long long v:adj[u])
{
dfs(v);
dp[u]=(dp[u]*dp[v])%mod;
}
}
void dfs2(long long u, long long x)
{
if (u>=n)
{
a[u]=x;
return;
}
vector<long long> vec;
long long sq=sqrt(adj[u].size());
for (long long i=0; i<adj[u].size(); i++)
{
long long v=adj[u][i];
if (i%sq==0)
vec.push_back(dp[v]);
else
vec[vec.size()-1]=(vec[vec.size()-1]*dp[v])%mod;
}
// cout << "vec: ";
// for (long long i=0; i<vec.size(); i++)
// cout << vec[i] << ' ';
// cout << '\n';
for (long long i=0; i<adj[u].size(); i++)
{
long long v=adj[u][i], y=x;
for (long long j=0; j<i/sq; j++)
y=(y*vec[j])%mod;
for (long long j=i/sq+1; j<vec.size(); j++)
y=(y*vec[j])%mod;
for (long long j=i/sq*sq; j<i; j++)
y=(y*dp[adj[u][j]])%mod;
for (long long j=i+1; j<min((long long)adj[u].size(), (i/sq+1)*sq); j++)
y=(y*dp[adj[u][j]])%mod;
dfs2(v, y);
}
}
void push(long long i, long long l, long long r)
{
if (lazy[i])
{
seg[i]=(sum[i]-seg[i]+mod)%mod;
lazy[i]=0;
lazy[i*2]^=1;
lazy[i*2+1]^=1;
}
}
void build(long long i, long long l, long long r)
{
if (l==r)
{
sum[i]=a[l];
seg[i]=a[l]*state[l];
// cout << "l r seg " << l << ' ' << r << ' ' << seg[i] << '\n';
return;
}
long long mid=(l+r)/2;
build(i*2, l, mid);
build(i*2+1, mid+1, r);
sum[i]=(sum[i*2]+sum[i*2+1])%mod;
seg[i]=(seg[i*2]+seg[i*2+1])%mod;
// cout << "l r seg " << l << ' ' << r << ' ' << seg[i] << '\n';
}
void update(long long i, long long l, long long r, long long ql, long long qr)
{
push(i, l, r);
if (ql<=l && r<=qr)
{
lazy[i]=1;
push(i, l, r);
// cout << "l r seg " << l << ' ' << r << ' ' << seg[i] << '\n';
return;
}
long long mid=(l+r)/2;
push(i*2, l, mid);
push(i*2+1, mid+1, r);
if (l<=qr && ql<=mid)
update(i*2, l, mid, ql, qr);
if (mid+1<=qr && ql<=r)
update(i*2+1, mid+1, r, ql, qr);
seg[i]=(seg[i*2]+seg[i*2+1])%mod;
// cout << "l r seg " << l << ' ' << r << ' ' << seg[i] << '\n';
}
void init(int N, int M, vector<int> P, vector<int> A)
{
n=N;
m=M;
for (long long i=1; i<n+m; i++)
adj[P[i]].push_back(i);
dfs(0);
dfs2(0, 1);
// cout << "a: ";
// for (long long i=0; i<m; i++)
// cout << a[i+n] << ' ';
// cout << '\n';
for (long long i=0; i<m; i++)
state[i+n]=A[i];
build(1, n, n+m-1);
}
int count_ways(int L, int R)
{
update(1, n, n+m-1, L, R);
return seg[1];
}
Compilation message
circuit.cpp: In function 'void dfs2(long long int, long long int)':
circuit.cpp:30:26: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
30 | for (long long i=0; i<adj[u].size(); i++)
| ~^~~~~~~~~~~~~~
circuit.cpp:42:26: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
42 | for (long long i=0; i<adj[u].size(); i++)
| ~^~~~~~~~~~~~~~
circuit.cpp:47:35: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
47 | for (long long j=i/sq+1; j<vec.size(); j++)
| ~^~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4944 KB |
Output is correct |
2 |
Correct |
3 ms |
4944 KB |
Output is correct |
3 |
Correct |
3 ms |
5072 KB |
Output is correct |
4 |
Correct |
3 ms |
5116 KB |
Output is correct |
5 |
Correct |
3 ms |
5072 KB |
Output is correct |
6 |
Correct |
3 ms |
5072 KB |
Output is correct |
7 |
Correct |
3 ms |
5072 KB |
Output is correct |
8 |
Correct |
3 ms |
5072 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4944 KB |
Output is correct |
2 |
Correct |
3 ms |
5080 KB |
Output is correct |
3 |
Correct |
4 ms |
5072 KB |
Output is correct |
4 |
Correct |
3 ms |
5072 KB |
Output is correct |
5 |
Correct |
3 ms |
5108 KB |
Output is correct |
6 |
Correct |
3 ms |
5072 KB |
Output is correct |
7 |
Correct |
3 ms |
5072 KB |
Output is correct |
8 |
Correct |
3 ms |
5072 KB |
Output is correct |
9 |
Correct |
3 ms |
5176 KB |
Output is correct |
10 |
Correct |
4 ms |
5312 KB |
Output is correct |
11 |
Correct |
4 ms |
5200 KB |
Output is correct |
12 |
Correct |
3 ms |
5072 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4944 KB |
Output is correct |
2 |
Correct |
3 ms |
4944 KB |
Output is correct |
3 |
Correct |
3 ms |
5072 KB |
Output is correct |
4 |
Correct |
3 ms |
5116 KB |
Output is correct |
5 |
Correct |
3 ms |
5072 KB |
Output is correct |
6 |
Correct |
3 ms |
5072 KB |
Output is correct |
7 |
Correct |
3 ms |
5072 KB |
Output is correct |
8 |
Correct |
3 ms |
5072 KB |
Output is correct |
9 |
Correct |
2 ms |
4944 KB |
Output is correct |
10 |
Correct |
3 ms |
5080 KB |
Output is correct |
11 |
Correct |
4 ms |
5072 KB |
Output is correct |
12 |
Correct |
3 ms |
5072 KB |
Output is correct |
13 |
Correct |
3 ms |
5108 KB |
Output is correct |
14 |
Correct |
3 ms |
5072 KB |
Output is correct |
15 |
Correct |
3 ms |
5072 KB |
Output is correct |
16 |
Correct |
3 ms |
5072 KB |
Output is correct |
17 |
Correct |
3 ms |
5176 KB |
Output is correct |
18 |
Correct |
4 ms |
5312 KB |
Output is correct |
19 |
Correct |
4 ms |
5200 KB |
Output is correct |
20 |
Correct |
3 ms |
5072 KB |
Output is correct |
21 |
Correct |
3 ms |
5072 KB |
Output is correct |
22 |
Correct |
3 ms |
5072 KB |
Output is correct |
23 |
Correct |
3 ms |
5072 KB |
Output is correct |
24 |
Correct |
4 ms |
5072 KB |
Output is correct |
25 |
Correct |
3 ms |
5180 KB |
Output is correct |
26 |
Correct |
4 ms |
5172 KB |
Output is correct |
27 |
Correct |
3 ms |
5072 KB |
Output is correct |
28 |
Correct |
3 ms |
5072 KB |
Output is correct |
29 |
Correct |
3 ms |
5072 KB |
Output is correct |
30 |
Correct |
3 ms |
5072 KB |
Output is correct |
31 |
Correct |
3 ms |
5200 KB |
Output is correct |
32 |
Correct |
3 ms |
5072 KB |
Output is correct |
33 |
Correct |
3 ms |
5072 KB |
Output is correct |
34 |
Correct |
3 ms |
5072 KB |
Output is correct |
35 |
Correct |
3 ms |
5200 KB |
Output is correct |
36 |
Correct |
3 ms |
5308 KB |
Output is correct |
37 |
Correct |
3 ms |
5328 KB |
Output is correct |
38 |
Correct |
3 ms |
5200 KB |
Output is correct |
39 |
Correct |
4 ms |
5072 KB |
Output is correct |
40 |
Correct |
3 ms |
5072 KB |
Output is correct |
41 |
Correct |
3 ms |
5072 KB |
Output is correct |
42 |
Correct |
3 ms |
5072 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
692 ms |
9276 KB |
Output is correct |
2 |
Correct |
727 ms |
13616 KB |
Output is correct |
3 |
Correct |
840 ms |
13500 KB |
Output is correct |
4 |
Correct |
871 ms |
13508 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
692 ms |
9276 KB |
Output is correct |
2 |
Correct |
727 ms |
13616 KB |
Output is correct |
3 |
Correct |
840 ms |
13500 KB |
Output is correct |
4 |
Correct |
871 ms |
13508 KB |
Output is correct |
5 |
Correct |
765 ms |
9532 KB |
Output is correct |
6 |
Correct |
960 ms |
14048 KB |
Output is correct |
7 |
Correct |
898 ms |
13952 KB |
Output is correct |
8 |
Correct |
856 ms |
12716 KB |
Output is correct |
9 |
Correct |
441 ms |
5328 KB |
Output is correct |
10 |
Correct |
973 ms |
5584 KB |
Output is correct |
11 |
Correct |
892 ms |
5584 KB |
Output is correct |
12 |
Correct |
778 ms |
5456 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4944 KB |
Output is correct |
2 |
Correct |
3 ms |
5080 KB |
Output is correct |
3 |
Correct |
4 ms |
5072 KB |
Output is correct |
4 |
Correct |
3 ms |
5072 KB |
Output is correct |
5 |
Correct |
3 ms |
5108 KB |
Output is correct |
6 |
Correct |
3 ms |
5072 KB |
Output is correct |
7 |
Correct |
3 ms |
5072 KB |
Output is correct |
8 |
Correct |
3 ms |
5072 KB |
Output is correct |
9 |
Correct |
3 ms |
5176 KB |
Output is correct |
10 |
Correct |
4 ms |
5312 KB |
Output is correct |
11 |
Correct |
4 ms |
5200 KB |
Output is correct |
12 |
Correct |
3 ms |
5072 KB |
Output is correct |
13 |
Correct |
692 ms |
9276 KB |
Output is correct |
14 |
Correct |
727 ms |
13616 KB |
Output is correct |
15 |
Correct |
840 ms |
13500 KB |
Output is correct |
16 |
Correct |
871 ms |
13508 KB |
Output is correct |
17 |
Correct |
765 ms |
9532 KB |
Output is correct |
18 |
Correct |
960 ms |
14048 KB |
Output is correct |
19 |
Correct |
898 ms |
13952 KB |
Output is correct |
20 |
Correct |
856 ms |
12716 KB |
Output is correct |
21 |
Correct |
441 ms |
5328 KB |
Output is correct |
22 |
Correct |
973 ms |
5584 KB |
Output is correct |
23 |
Correct |
892 ms |
5584 KB |
Output is correct |
24 |
Correct |
778 ms |
5456 KB |
Output is correct |
25 |
Incorrect |
1053 ms |
19568 KB |
101st lines differ - on the 1st token, expected: '74137646', found: '74137647' |
26 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4944 KB |
Output is correct |
2 |
Correct |
3 ms |
4944 KB |
Output is correct |
3 |
Correct |
3 ms |
5072 KB |
Output is correct |
4 |
Correct |
3 ms |
5116 KB |
Output is correct |
5 |
Correct |
3 ms |
5072 KB |
Output is correct |
6 |
Correct |
3 ms |
5072 KB |
Output is correct |
7 |
Correct |
3 ms |
5072 KB |
Output is correct |
8 |
Correct |
3 ms |
5072 KB |
Output is correct |
9 |
Correct |
2 ms |
4944 KB |
Output is correct |
10 |
Correct |
3 ms |
5080 KB |
Output is correct |
11 |
Correct |
4 ms |
5072 KB |
Output is correct |
12 |
Correct |
3 ms |
5072 KB |
Output is correct |
13 |
Correct |
3 ms |
5108 KB |
Output is correct |
14 |
Correct |
3 ms |
5072 KB |
Output is correct |
15 |
Correct |
3 ms |
5072 KB |
Output is correct |
16 |
Correct |
3 ms |
5072 KB |
Output is correct |
17 |
Correct |
3 ms |
5176 KB |
Output is correct |
18 |
Correct |
4 ms |
5312 KB |
Output is correct |
19 |
Correct |
4 ms |
5200 KB |
Output is correct |
20 |
Correct |
3 ms |
5072 KB |
Output is correct |
21 |
Correct |
3 ms |
5072 KB |
Output is correct |
22 |
Correct |
3 ms |
5072 KB |
Output is correct |
23 |
Correct |
3 ms |
5072 KB |
Output is correct |
24 |
Correct |
4 ms |
5072 KB |
Output is correct |
25 |
Correct |
3 ms |
5180 KB |
Output is correct |
26 |
Correct |
4 ms |
5172 KB |
Output is correct |
27 |
Correct |
3 ms |
5072 KB |
Output is correct |
28 |
Correct |
3 ms |
5072 KB |
Output is correct |
29 |
Correct |
3 ms |
5072 KB |
Output is correct |
30 |
Correct |
3 ms |
5072 KB |
Output is correct |
31 |
Correct |
3 ms |
5200 KB |
Output is correct |
32 |
Correct |
3 ms |
5072 KB |
Output is correct |
33 |
Correct |
3 ms |
5072 KB |
Output is correct |
34 |
Correct |
3 ms |
5072 KB |
Output is correct |
35 |
Correct |
3 ms |
5200 KB |
Output is correct |
36 |
Correct |
3 ms |
5308 KB |
Output is correct |
37 |
Correct |
3 ms |
5328 KB |
Output is correct |
38 |
Correct |
3 ms |
5200 KB |
Output is correct |
39 |
Correct |
4 ms |
5072 KB |
Output is correct |
40 |
Correct |
3 ms |
5072 KB |
Output is correct |
41 |
Correct |
3 ms |
5072 KB |
Output is correct |
42 |
Correct |
3 ms |
5072 KB |
Output is correct |
43 |
Correct |
703 ms |
5456 KB |
Output is correct |
44 |
Correct |
743 ms |
5584 KB |
Output is correct |
45 |
Correct |
790 ms |
5584 KB |
Output is correct |
46 |
Correct |
984 ms |
5968 KB |
Output is correct |
47 |
Correct |
995 ms |
6096 KB |
Output is correct |
48 |
Correct |
702 ms |
5968 KB |
Output is correct |
49 |
Correct |
878 ms |
5968 KB |
Output is correct |
50 |
Correct |
927 ms |
5712 KB |
Output is correct |
51 |
Correct |
819 ms |
5604 KB |
Output is correct |
52 |
Correct |
839 ms |
5888 KB |
Output is correct |
53 |
Correct |
619 ms |
5904 KB |
Output is correct |
54 |
Correct |
919 ms |
5968 KB |
Output is correct |
55 |
Correct |
935 ms |
5840 KB |
Output is correct |
56 |
Correct |
735 ms |
5768 KB |
Output is correct |
57 |
Correct |
942 ms |
5792 KB |
Output is correct |
58 |
Correct |
826 ms |
6608 KB |
Output is correct |
59 |
Correct |
849 ms |
6672 KB |
Output is correct |
60 |
Correct |
761 ms |
6496 KB |
Output is correct |
61 |
Correct |
891 ms |
5732 KB |
Output is correct |
62 |
Correct |
1043 ms |
5464 KB |
Output is correct |
63 |
Correct |
964 ms |
5544 KB |
Output is correct |
64 |
Correct |
647 ms |
5808 KB |
Output is correct |
65 |
Correct |
462 ms |
5328 KB |
Output is correct |
66 |
Correct |
1034 ms |
5592 KB |
Output is correct |
67 |
Correct |
734 ms |
5552 KB |
Output is correct |
68 |
Correct |
697 ms |
5456 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4944 KB |
Output is correct |
2 |
Correct |
3 ms |
4944 KB |
Output is correct |
3 |
Correct |
3 ms |
5072 KB |
Output is correct |
4 |
Correct |
3 ms |
5116 KB |
Output is correct |
5 |
Correct |
3 ms |
5072 KB |
Output is correct |
6 |
Correct |
3 ms |
5072 KB |
Output is correct |
7 |
Correct |
3 ms |
5072 KB |
Output is correct |
8 |
Correct |
3 ms |
5072 KB |
Output is correct |
9 |
Correct |
2 ms |
4944 KB |
Output is correct |
10 |
Correct |
3 ms |
5080 KB |
Output is correct |
11 |
Correct |
4 ms |
5072 KB |
Output is correct |
12 |
Correct |
3 ms |
5072 KB |
Output is correct |
13 |
Correct |
3 ms |
5108 KB |
Output is correct |
14 |
Correct |
3 ms |
5072 KB |
Output is correct |
15 |
Correct |
3 ms |
5072 KB |
Output is correct |
16 |
Correct |
3 ms |
5072 KB |
Output is correct |
17 |
Correct |
3 ms |
5176 KB |
Output is correct |
18 |
Correct |
4 ms |
5312 KB |
Output is correct |
19 |
Correct |
4 ms |
5200 KB |
Output is correct |
20 |
Correct |
3 ms |
5072 KB |
Output is correct |
21 |
Correct |
3 ms |
5072 KB |
Output is correct |
22 |
Correct |
3 ms |
5072 KB |
Output is correct |
23 |
Correct |
3 ms |
5072 KB |
Output is correct |
24 |
Correct |
4 ms |
5072 KB |
Output is correct |
25 |
Correct |
3 ms |
5180 KB |
Output is correct |
26 |
Correct |
4 ms |
5172 KB |
Output is correct |
27 |
Correct |
3 ms |
5072 KB |
Output is correct |
28 |
Correct |
3 ms |
5072 KB |
Output is correct |
29 |
Correct |
3 ms |
5072 KB |
Output is correct |
30 |
Correct |
3 ms |
5072 KB |
Output is correct |
31 |
Correct |
3 ms |
5200 KB |
Output is correct |
32 |
Correct |
3 ms |
5072 KB |
Output is correct |
33 |
Correct |
3 ms |
5072 KB |
Output is correct |
34 |
Correct |
3 ms |
5072 KB |
Output is correct |
35 |
Correct |
3 ms |
5200 KB |
Output is correct |
36 |
Correct |
3 ms |
5308 KB |
Output is correct |
37 |
Correct |
3 ms |
5328 KB |
Output is correct |
38 |
Correct |
3 ms |
5200 KB |
Output is correct |
39 |
Correct |
4 ms |
5072 KB |
Output is correct |
40 |
Correct |
3 ms |
5072 KB |
Output is correct |
41 |
Correct |
3 ms |
5072 KB |
Output is correct |
42 |
Correct |
3 ms |
5072 KB |
Output is correct |
43 |
Correct |
692 ms |
9276 KB |
Output is correct |
44 |
Correct |
727 ms |
13616 KB |
Output is correct |
45 |
Correct |
840 ms |
13500 KB |
Output is correct |
46 |
Correct |
871 ms |
13508 KB |
Output is correct |
47 |
Correct |
765 ms |
9532 KB |
Output is correct |
48 |
Correct |
960 ms |
14048 KB |
Output is correct |
49 |
Correct |
898 ms |
13952 KB |
Output is correct |
50 |
Correct |
856 ms |
12716 KB |
Output is correct |
51 |
Correct |
441 ms |
5328 KB |
Output is correct |
52 |
Correct |
973 ms |
5584 KB |
Output is correct |
53 |
Correct |
892 ms |
5584 KB |
Output is correct |
54 |
Correct |
778 ms |
5456 KB |
Output is correct |
55 |
Incorrect |
1053 ms |
19568 KB |
101st lines differ - on the 1st token, expected: '74137646', found: '74137647' |
56 |
Halted |
0 ms |
0 KB |
- |