#include "circuit.h"
#include <bits/stdc++.h>
using namespace std;
const int N=100'000,mod=1e9+2022;
#define int long long
int add(int x,int y)
{
assert(y>=0 && y<mod);
assert(x>=0 && x<mod);
return (x+y)%mod;
}
void add_self(int& x,int y)
{
assert(y>=0 && y<mod);
assert(x>=0 && x<mod);
x+=y;
if(x>=mod)
{
x-=mod;
}
if(x<0)
{
x+=mod;
}
}
int prod(int x,int y)
{
assert(y>=0 && y<mod);
assert(x>=0 && x<mod);
return (1LL*x*y)%mod;
}
int n,m;
vector<signed>g[2*N],a;
bool lazy[5*N];
int aint[5*N][2],dp[2*N],produs[2*N];
void push_down(int nod)
{
if(lazy[nod])
{
swap(aint[2*nod+1][0] , aint[2*nod+1][1]);
swap(aint[2*nod+2][0] , aint[2*nod+2][1]);
lazy[2*nod+1]^=true;
lazy[2*nod+2]^=true;
lazy[nod]=false;
}
}
void recalc(int nod)
{
int l=2*nod+1,r=2*nod+2;
aint[nod][0]=add(aint[l][0],aint[r][0]);
aint[nod][1]=add(aint[l][1],aint[r][1]);
}
void build(int nod,int st,int dr)
{
if(st==dr)
{
aint[nod][a[st]^1]=dp[st+n];
return;
}
int m=(st+dr)/2;
build(2*nod+1,st,m);
build(2*nod+2,m+1,dr);
recalc(nod);
}
void update(int nod,int st,int dr,int l,int r)
{
if(st>r || dr<l)
{
return;
}
if(l<=st && dr<=r)
{
lazy[nod]^=true;
swap(aint[nod][0] , aint[nod][1]);
return;
}
int m=(st+dr)/2;
push_down(nod);
update(2*nod+1,st,m,l,r);
update(2*nod+2,m+1,dr,l,r);
recalc(nod);
}
void dfs1(int nod)
{
produs[nod]=max(1LL,(int)g[nod].size());
for(auto &c:g[nod])
{
dfs1(c);
produs[nod]=prod(produs[nod] , produs[c]);
}
}
void dfs2(int nod)
{
int sz=(int)g[nod].size();
if(g[nod].empty())
{
return;
}
vector<int>suf(sz,1),pref(sz,1);
for(int i=1;i<sz;i++)
{
suf[i]=prod(suf[i-1],produs[g[nod][i-1]]);
}
for(int i=sz-2;i>=0;i--)
{
pref[i]=prod(pref[i+1],produs[g[nod][i+1]]);
}
for(int i=0;i<sz;i++)
{
int c=g[nod][i];
dp[c]=prod(dp[nod] , prod(suf[i] , pref[i]));
dfs2(c);
}
}
void init(signed nn, signed mm, std::vector<signed> pp, std::vector<signed> init_a)
{
n=nn;
m=mm;
for(int i=1;i<n+m;i++)
{
g[pp[i]].push_back(i);
}
a=init_a;
dp[0]=1;
dfs1(0);
dfs2(0);
build(0,0,m-1);
}
signed count_ways(signed l, signed r)
{
l-=n;
r-=n;
update(0,0,m-1,l,r);
return aint[0][0];
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
10064 KB |
Output is correct |
2 |
Correct |
3 ms |
10064 KB |
Output is correct |
3 |
Correct |
3 ms |
10064 KB |
Output is correct |
4 |
Correct |
3 ms |
10064 KB |
Output is correct |
5 |
Correct |
3 ms |
10064 KB |
Output is correct |
6 |
Correct |
3 ms |
10064 KB |
Output is correct |
7 |
Correct |
4 ms |
10064 KB |
Output is correct |
8 |
Correct |
3 ms |
10064 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
10064 KB |
Output is correct |
2 |
Correct |
3 ms |
10064 KB |
Output is correct |
3 |
Correct |
3 ms |
10064 KB |
Output is correct |
4 |
Correct |
3 ms |
10064 KB |
Output is correct |
5 |
Correct |
4 ms |
10232 KB |
Output is correct |
6 |
Correct |
3 ms |
10064 KB |
Output is correct |
7 |
Correct |
4 ms |
10320 KB |
Output is correct |
8 |
Correct |
4 ms |
10320 KB |
Output is correct |
9 |
Correct |
3 ms |
10320 KB |
Output is correct |
10 |
Correct |
5 ms |
10320 KB |
Output is correct |
11 |
Correct |
3 ms |
10320 KB |
Output is correct |
12 |
Correct |
3 ms |
10064 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
10064 KB |
Output is correct |
2 |
Correct |
3 ms |
10064 KB |
Output is correct |
3 |
Correct |
3 ms |
10064 KB |
Output is correct |
4 |
Correct |
3 ms |
10064 KB |
Output is correct |
5 |
Correct |
3 ms |
10064 KB |
Output is correct |
6 |
Correct |
3 ms |
10064 KB |
Output is correct |
7 |
Correct |
4 ms |
10064 KB |
Output is correct |
8 |
Correct |
3 ms |
10064 KB |
Output is correct |
9 |
Correct |
3 ms |
10064 KB |
Output is correct |
10 |
Correct |
3 ms |
10064 KB |
Output is correct |
11 |
Correct |
3 ms |
10064 KB |
Output is correct |
12 |
Correct |
3 ms |
10064 KB |
Output is correct |
13 |
Correct |
4 ms |
10232 KB |
Output is correct |
14 |
Correct |
3 ms |
10064 KB |
Output is correct |
15 |
Correct |
4 ms |
10320 KB |
Output is correct |
16 |
Correct |
4 ms |
10320 KB |
Output is correct |
17 |
Correct |
3 ms |
10320 KB |
Output is correct |
18 |
Correct |
5 ms |
10320 KB |
Output is correct |
19 |
Correct |
3 ms |
10320 KB |
Output is correct |
20 |
Correct |
3 ms |
10064 KB |
Output is correct |
21 |
Correct |
5 ms |
10064 KB |
Output is correct |
22 |
Correct |
4 ms |
10064 KB |
Output is correct |
23 |
Correct |
4 ms |
10064 KB |
Output is correct |
24 |
Correct |
4 ms |
10320 KB |
Output is correct |
25 |
Correct |
4 ms |
10320 KB |
Output is correct |
26 |
Correct |
4 ms |
10320 KB |
Output is correct |
27 |
Correct |
5 ms |
10320 KB |
Output is correct |
28 |
Correct |
4 ms |
10320 KB |
Output is correct |
29 |
Correct |
3 ms |
10064 KB |
Output is correct |
30 |
Correct |
3 ms |
10064 KB |
Output is correct |
31 |
Correct |
3 ms |
10320 KB |
Output is correct |
32 |
Correct |
4 ms |
10320 KB |
Output is correct |
33 |
Correct |
3 ms |
10064 KB |
Output is correct |
34 |
Correct |
3 ms |
10064 KB |
Output is correct |
35 |
Correct |
3 ms |
10064 KB |
Output is correct |
36 |
Correct |
5 ms |
10320 KB |
Output is correct |
37 |
Correct |
3 ms |
10320 KB |
Output is correct |
38 |
Correct |
4 ms |
10320 KB |
Output is correct |
39 |
Correct |
3 ms |
10492 KB |
Output is correct |
40 |
Correct |
3 ms |
10064 KB |
Output is correct |
41 |
Correct |
3 ms |
10064 KB |
Output is correct |
42 |
Correct |
3 ms |
10064 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1424 ms |
12168 KB |
Output is correct |
2 |
Correct |
1985 ms |
16200 KB |
Output is correct |
3 |
Correct |
1926 ms |
16136 KB |
Output is correct |
4 |
Correct |
1998 ms |
16208 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1424 ms |
12168 KB |
Output is correct |
2 |
Correct |
1985 ms |
16200 KB |
Output is correct |
3 |
Correct |
1926 ms |
16136 KB |
Output is correct |
4 |
Correct |
1998 ms |
16208 KB |
Output is correct |
5 |
Correct |
1588 ms |
12368 KB |
Output is correct |
6 |
Correct |
1991 ms |
16208 KB |
Output is correct |
7 |
Correct |
1978 ms |
16208 KB |
Output is correct |
8 |
Correct |
1929 ms |
16208 KB |
Output is correct |
9 |
Correct |
942 ms |
10320 KB |
Output is correct |
10 |
Correct |
1911 ms |
10320 KB |
Output is correct |
11 |
Correct |
1886 ms |
10320 KB |
Output is correct |
12 |
Correct |
1929 ms |
10320 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
10064 KB |
Output is correct |
2 |
Correct |
3 ms |
10064 KB |
Output is correct |
3 |
Correct |
3 ms |
10064 KB |
Output is correct |
4 |
Correct |
3 ms |
10064 KB |
Output is correct |
5 |
Correct |
4 ms |
10232 KB |
Output is correct |
6 |
Correct |
3 ms |
10064 KB |
Output is correct |
7 |
Correct |
4 ms |
10320 KB |
Output is correct |
8 |
Correct |
4 ms |
10320 KB |
Output is correct |
9 |
Correct |
3 ms |
10320 KB |
Output is correct |
10 |
Correct |
5 ms |
10320 KB |
Output is correct |
11 |
Correct |
3 ms |
10320 KB |
Output is correct |
12 |
Correct |
3 ms |
10064 KB |
Output is correct |
13 |
Correct |
1424 ms |
12168 KB |
Output is correct |
14 |
Correct |
1985 ms |
16200 KB |
Output is correct |
15 |
Correct |
1926 ms |
16136 KB |
Output is correct |
16 |
Correct |
1998 ms |
16208 KB |
Output is correct |
17 |
Correct |
1588 ms |
12368 KB |
Output is correct |
18 |
Correct |
1991 ms |
16208 KB |
Output is correct |
19 |
Correct |
1978 ms |
16208 KB |
Output is correct |
20 |
Correct |
1929 ms |
16208 KB |
Output is correct |
21 |
Correct |
942 ms |
10320 KB |
Output is correct |
22 |
Correct |
1911 ms |
10320 KB |
Output is correct |
23 |
Correct |
1886 ms |
10320 KB |
Output is correct |
24 |
Correct |
1929 ms |
10320 KB |
Output is correct |
25 |
Correct |
1983 ms |
20100 KB |
Output is correct |
26 |
Correct |
2043 ms |
20368 KB |
Output is correct |
27 |
Correct |
2005 ms |
20304 KB |
Output is correct |
28 |
Correct |
1657 ms |
20376 KB |
Output is correct |
29 |
Correct |
1992 ms |
38984 KB |
Output is correct |
30 |
Correct |
1630 ms |
38984 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
10064 KB |
Output is correct |
2 |
Correct |
3 ms |
10064 KB |
Output is correct |
3 |
Correct |
3 ms |
10064 KB |
Output is correct |
4 |
Correct |
3 ms |
10064 KB |
Output is correct |
5 |
Correct |
3 ms |
10064 KB |
Output is correct |
6 |
Correct |
3 ms |
10064 KB |
Output is correct |
7 |
Correct |
4 ms |
10064 KB |
Output is correct |
8 |
Correct |
3 ms |
10064 KB |
Output is correct |
9 |
Correct |
3 ms |
10064 KB |
Output is correct |
10 |
Correct |
3 ms |
10064 KB |
Output is correct |
11 |
Correct |
3 ms |
10064 KB |
Output is correct |
12 |
Correct |
3 ms |
10064 KB |
Output is correct |
13 |
Correct |
4 ms |
10232 KB |
Output is correct |
14 |
Correct |
3 ms |
10064 KB |
Output is correct |
15 |
Correct |
4 ms |
10320 KB |
Output is correct |
16 |
Correct |
4 ms |
10320 KB |
Output is correct |
17 |
Correct |
3 ms |
10320 KB |
Output is correct |
18 |
Correct |
5 ms |
10320 KB |
Output is correct |
19 |
Correct |
3 ms |
10320 KB |
Output is correct |
20 |
Correct |
3 ms |
10064 KB |
Output is correct |
21 |
Correct |
5 ms |
10064 KB |
Output is correct |
22 |
Correct |
4 ms |
10064 KB |
Output is correct |
23 |
Correct |
4 ms |
10064 KB |
Output is correct |
24 |
Correct |
4 ms |
10320 KB |
Output is correct |
25 |
Correct |
4 ms |
10320 KB |
Output is correct |
26 |
Correct |
4 ms |
10320 KB |
Output is correct |
27 |
Correct |
5 ms |
10320 KB |
Output is correct |
28 |
Correct |
4 ms |
10320 KB |
Output is correct |
29 |
Correct |
3 ms |
10064 KB |
Output is correct |
30 |
Correct |
3 ms |
10064 KB |
Output is correct |
31 |
Correct |
3 ms |
10320 KB |
Output is correct |
32 |
Correct |
4 ms |
10320 KB |
Output is correct |
33 |
Correct |
3 ms |
10064 KB |
Output is correct |
34 |
Correct |
3 ms |
10064 KB |
Output is correct |
35 |
Correct |
3 ms |
10064 KB |
Output is correct |
36 |
Correct |
5 ms |
10320 KB |
Output is correct |
37 |
Correct |
3 ms |
10320 KB |
Output is correct |
38 |
Correct |
4 ms |
10320 KB |
Output is correct |
39 |
Correct |
3 ms |
10492 KB |
Output is correct |
40 |
Correct |
3 ms |
10064 KB |
Output is correct |
41 |
Correct |
3 ms |
10064 KB |
Output is correct |
42 |
Correct |
3 ms |
10064 KB |
Output is correct |
43 |
Correct |
1341 ms |
10320 KB |
Output is correct |
44 |
Correct |
1848 ms |
10320 KB |
Output is correct |
45 |
Correct |
1946 ms |
10320 KB |
Output is correct |
46 |
Correct |
1957 ms |
10576 KB |
Output is correct |
47 |
Correct |
1911 ms |
10576 KB |
Output is correct |
48 |
Correct |
1959 ms |
10576 KB |
Output is correct |
49 |
Correct |
1934 ms |
10576 KB |
Output is correct |
50 |
Correct |
1878 ms |
10576 KB |
Output is correct |
51 |
Correct |
1883 ms |
10492 KB |
Output is correct |
52 |
Correct |
1871 ms |
10488 KB |
Output is correct |
53 |
Correct |
1775 ms |
11344 KB |
Output is correct |
54 |
Correct |
1880 ms |
10576 KB |
Output is correct |
55 |
Correct |
1800 ms |
10320 KB |
Output is correct |
56 |
Correct |
1886 ms |
10320 KB |
Output is correct |
57 |
Correct |
1893 ms |
10320 KB |
Output is correct |
58 |
Correct |
1927 ms |
11344 KB |
Output is correct |
59 |
Correct |
1917 ms |
11600 KB |
Output is correct |
60 |
Correct |
1913 ms |
11600 KB |
Output is correct |
61 |
Correct |
1878 ms |
10576 KB |
Output is correct |
62 |
Correct |
1906 ms |
10320 KB |
Output is correct |
63 |
Correct |
1871 ms |
10320 KB |
Output is correct |
64 |
Correct |
1881 ms |
10320 KB |
Output is correct |
65 |
Correct |
933 ms |
10320 KB |
Output is correct |
66 |
Correct |
1821 ms |
10320 KB |
Output is correct |
67 |
Correct |
1904 ms |
10320 KB |
Output is correct |
68 |
Correct |
1893 ms |
10320 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
10064 KB |
Output is correct |
2 |
Correct |
3 ms |
10064 KB |
Output is correct |
3 |
Correct |
3 ms |
10064 KB |
Output is correct |
4 |
Correct |
3 ms |
10064 KB |
Output is correct |
5 |
Correct |
3 ms |
10064 KB |
Output is correct |
6 |
Correct |
3 ms |
10064 KB |
Output is correct |
7 |
Correct |
4 ms |
10064 KB |
Output is correct |
8 |
Correct |
3 ms |
10064 KB |
Output is correct |
9 |
Correct |
3 ms |
10064 KB |
Output is correct |
10 |
Correct |
3 ms |
10064 KB |
Output is correct |
11 |
Correct |
3 ms |
10064 KB |
Output is correct |
12 |
Correct |
3 ms |
10064 KB |
Output is correct |
13 |
Correct |
4 ms |
10232 KB |
Output is correct |
14 |
Correct |
3 ms |
10064 KB |
Output is correct |
15 |
Correct |
4 ms |
10320 KB |
Output is correct |
16 |
Correct |
4 ms |
10320 KB |
Output is correct |
17 |
Correct |
3 ms |
10320 KB |
Output is correct |
18 |
Correct |
5 ms |
10320 KB |
Output is correct |
19 |
Correct |
3 ms |
10320 KB |
Output is correct |
20 |
Correct |
3 ms |
10064 KB |
Output is correct |
21 |
Correct |
5 ms |
10064 KB |
Output is correct |
22 |
Correct |
4 ms |
10064 KB |
Output is correct |
23 |
Correct |
4 ms |
10064 KB |
Output is correct |
24 |
Correct |
4 ms |
10320 KB |
Output is correct |
25 |
Correct |
4 ms |
10320 KB |
Output is correct |
26 |
Correct |
4 ms |
10320 KB |
Output is correct |
27 |
Correct |
5 ms |
10320 KB |
Output is correct |
28 |
Correct |
4 ms |
10320 KB |
Output is correct |
29 |
Correct |
3 ms |
10064 KB |
Output is correct |
30 |
Correct |
3 ms |
10064 KB |
Output is correct |
31 |
Correct |
3 ms |
10320 KB |
Output is correct |
32 |
Correct |
4 ms |
10320 KB |
Output is correct |
33 |
Correct |
3 ms |
10064 KB |
Output is correct |
34 |
Correct |
3 ms |
10064 KB |
Output is correct |
35 |
Correct |
3 ms |
10064 KB |
Output is correct |
36 |
Correct |
5 ms |
10320 KB |
Output is correct |
37 |
Correct |
3 ms |
10320 KB |
Output is correct |
38 |
Correct |
4 ms |
10320 KB |
Output is correct |
39 |
Correct |
3 ms |
10492 KB |
Output is correct |
40 |
Correct |
3 ms |
10064 KB |
Output is correct |
41 |
Correct |
3 ms |
10064 KB |
Output is correct |
42 |
Correct |
3 ms |
10064 KB |
Output is correct |
43 |
Correct |
1424 ms |
12168 KB |
Output is correct |
44 |
Correct |
1985 ms |
16200 KB |
Output is correct |
45 |
Correct |
1926 ms |
16136 KB |
Output is correct |
46 |
Correct |
1998 ms |
16208 KB |
Output is correct |
47 |
Correct |
1588 ms |
12368 KB |
Output is correct |
48 |
Correct |
1991 ms |
16208 KB |
Output is correct |
49 |
Correct |
1978 ms |
16208 KB |
Output is correct |
50 |
Correct |
1929 ms |
16208 KB |
Output is correct |
51 |
Correct |
942 ms |
10320 KB |
Output is correct |
52 |
Correct |
1911 ms |
10320 KB |
Output is correct |
53 |
Correct |
1886 ms |
10320 KB |
Output is correct |
54 |
Correct |
1929 ms |
10320 KB |
Output is correct |
55 |
Correct |
1983 ms |
20100 KB |
Output is correct |
56 |
Correct |
2043 ms |
20368 KB |
Output is correct |
57 |
Correct |
2005 ms |
20304 KB |
Output is correct |
58 |
Correct |
1657 ms |
20376 KB |
Output is correct |
59 |
Correct |
1992 ms |
38984 KB |
Output is correct |
60 |
Correct |
1630 ms |
38984 KB |
Output is correct |
61 |
Correct |
1341 ms |
10320 KB |
Output is correct |
62 |
Correct |
1848 ms |
10320 KB |
Output is correct |
63 |
Correct |
1946 ms |
10320 KB |
Output is correct |
64 |
Correct |
1957 ms |
10576 KB |
Output is correct |
65 |
Correct |
1911 ms |
10576 KB |
Output is correct |
66 |
Correct |
1959 ms |
10576 KB |
Output is correct |
67 |
Correct |
1934 ms |
10576 KB |
Output is correct |
68 |
Correct |
1878 ms |
10576 KB |
Output is correct |
69 |
Correct |
1883 ms |
10492 KB |
Output is correct |
70 |
Correct |
1871 ms |
10488 KB |
Output is correct |
71 |
Correct |
1775 ms |
11344 KB |
Output is correct |
72 |
Correct |
1880 ms |
10576 KB |
Output is correct |
73 |
Correct |
1800 ms |
10320 KB |
Output is correct |
74 |
Correct |
1886 ms |
10320 KB |
Output is correct |
75 |
Correct |
1893 ms |
10320 KB |
Output is correct |
76 |
Correct |
1927 ms |
11344 KB |
Output is correct |
77 |
Correct |
1917 ms |
11600 KB |
Output is correct |
78 |
Correct |
1913 ms |
11600 KB |
Output is correct |
79 |
Correct |
1878 ms |
10576 KB |
Output is correct |
80 |
Correct |
1906 ms |
10320 KB |
Output is correct |
81 |
Correct |
1871 ms |
10320 KB |
Output is correct |
82 |
Correct |
1881 ms |
10320 KB |
Output is correct |
83 |
Correct |
933 ms |
10320 KB |
Output is correct |
84 |
Correct |
1821 ms |
10320 KB |
Output is correct |
85 |
Correct |
1904 ms |
10320 KB |
Output is correct |
86 |
Correct |
1893 ms |
10320 KB |
Output is correct |
87 |
Correct |
3 ms |
10064 KB |
Output is correct |
88 |
Correct |
1203 ms |
19784 KB |
Output is correct |
89 |
Correct |
2027 ms |
16508 KB |
Output is correct |
90 |
Correct |
2029 ms |
16200 KB |
Output is correct |
91 |
Correct |
1912 ms |
20296 KB |
Output is correct |
92 |
Correct |
2081 ms |
20296 KB |
Output is correct |
93 |
Correct |
2051 ms |
20372 KB |
Output is correct |
94 |
Correct |
2089 ms |
20296 KB |
Output is correct |
95 |
Correct |
1922 ms |
20388 KB |
Output is correct |
96 |
Correct |
1820 ms |
16808 KB |
Output is correct |
97 |
Correct |
1955 ms |
17004 KB |
Output is correct |
98 |
Correct |
1814 ms |
32932 KB |
Output is correct |
99 |
Correct |
2017 ms |
20296 KB |
Output is correct |
100 |
Correct |
2067 ms |
18428 KB |
Output is correct |
101 |
Correct |
2080 ms |
17772 KB |
Output is correct |
102 |
Correct |
1971 ms |
16976 KB |
Output is correct |
103 |
Correct |
2073 ms |
39060 KB |
Output is correct |
104 |
Correct |
2031 ms |
39412 KB |
Output is correct |
105 |
Correct |
2001 ms |
39408 KB |
Output is correct |
106 |
Correct |
1947 ms |
20304 KB |
Output is correct |
107 |
Correct |
1962 ms |
17464 KB |
Output is correct |
108 |
Correct |
2005 ms |
17224 KB |
Output is correct |
109 |
Correct |
1946 ms |
16976 KB |
Output is correct |