#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define st first
#define nd second
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define ll long long
ll mod=1000002022;
int inf=1000000007;
ll infl=1000000000000000007;
const int N=200007,pot=1<<18;
bool is[N];
vector<int>G[N];
ll ile[N];
vector<ll> P[N];
vector<ll> S[N];
ll seg[2*pot+7][2];
bool lzy[2*pot+7];
void push(int v)
{
if(lzy[v])
{
swap(seg[2*v][0],seg[2*v][1]);
swap(seg[2*v+1][0],seg[2*v+1][1]);
lzy[2*v]^=1;
lzy[2*v+1]^=1;
lzy[v]=0;
}
}
void ins(int v,int a,int b,int l,int r)
{
if(a<=l&&b>=r)
{
swap(seg[v][0],seg[v][1]);
lzy[v]^=1;
return ;
}
if(r<a||l>b) return ;
push(v);
ins(2*v,a,b,l,(l+r)/2);
ins(2*v+1,a,b,(l+r)/2+1,r);
seg[v][0]=seg[2*v][0]+seg[2*v+1][0];
seg[v][1]=seg[2*v][1]+seg[2*v+1][1];
}
int n,m;
void dfs(int v)
{
ile[v]=max(1,sz(G[v]));
for(auto u:G[v])
{
dfs(u);
ile[v]=ile[v]*ile[u]%mod;
}
}
void dfs1(int v,ll c)
{
if(sz(G[v])==0)
{
seg[v+pot-1][is[v]]=c;
return ;
}
P[v].resize(sz(G[v])+2,1);
for(int i=0;i<sz(G[v]);i++) P[v][i+1]=P[v][i]*ile[G[v][i]]%mod;
S[v].resize(sz(G[v])+2,1);
for(int i=sz(G[v])-1;i>=0;i--) S[v][i+1]=S[v][i+2]*ile[G[v][i]]%mod;
for(int i=0;i<sz(G[v]);i++)
{
dfs1(G[v][i],c*P[v][i]%mod*S[v][i+2]%mod);
}
for(int i=pot-1;i>0;i--)
{
seg[i][0]=(seg[2*i][0]+seg[2*i+1][0])%mod;
seg[i][1]=(seg[2*i][1]+seg[2*i+1][1])%mod;
}
}
void init(int N,int M,vector<int>p,vector<int>a)
{
n=N,m=M;
for(int i=0;i<m;i++) is[i+n]=a[i];
for(int i=1;i<n+m;i++) G[p[i]].pb(i);
dfs(0);
dfs1(0,1);
}
int count_ways(int l,int r)
{
ins(1,l,r,1,pot);
return seg[1][1]%mod;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
18512 KB |
Output is correct |
2 |
Correct |
13 ms |
18512 KB |
Output is correct |
3 |
Correct |
13 ms |
18512 KB |
Output is correct |
4 |
Correct |
14 ms |
18512 KB |
Output is correct |
5 |
Correct |
12 ms |
18512 KB |
Output is correct |
6 |
Correct |
14 ms |
18608 KB |
Output is correct |
7 |
Correct |
12 ms |
18512 KB |
Output is correct |
8 |
Correct |
12 ms |
18512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
18528 KB |
Output is correct |
2 |
Correct |
659 ms |
18660 KB |
Output is correct |
3 |
Correct |
1281 ms |
18796 KB |
Output is correct |
4 |
Correct |
1280 ms |
18672 KB |
Output is correct |
5 |
Correct |
1260 ms |
18676 KB |
Output is correct |
6 |
Correct |
1808 ms |
18600 KB |
Output is correct |
7 |
Correct |
2426 ms |
18588 KB |
Output is correct |
8 |
Correct |
2393 ms |
18604 KB |
Output is correct |
9 |
Correct |
2390 ms |
18768 KB |
Output is correct |
10 |
Correct |
2433 ms |
18768 KB |
Output is correct |
11 |
Correct |
2386 ms |
18892 KB |
Output is correct |
12 |
Correct |
2017 ms |
18640 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
18512 KB |
Output is correct |
2 |
Correct |
13 ms |
18512 KB |
Output is correct |
3 |
Correct |
13 ms |
18512 KB |
Output is correct |
4 |
Correct |
14 ms |
18512 KB |
Output is correct |
5 |
Correct |
12 ms |
18512 KB |
Output is correct |
6 |
Correct |
14 ms |
18608 KB |
Output is correct |
7 |
Correct |
12 ms |
18512 KB |
Output is correct |
8 |
Correct |
12 ms |
18512 KB |
Output is correct |
9 |
Correct |
13 ms |
18528 KB |
Output is correct |
10 |
Correct |
659 ms |
18660 KB |
Output is correct |
11 |
Correct |
1281 ms |
18796 KB |
Output is correct |
12 |
Correct |
1280 ms |
18672 KB |
Output is correct |
13 |
Correct |
1260 ms |
18676 KB |
Output is correct |
14 |
Correct |
1808 ms |
18600 KB |
Output is correct |
15 |
Correct |
2426 ms |
18588 KB |
Output is correct |
16 |
Correct |
2393 ms |
18604 KB |
Output is correct |
17 |
Correct |
2390 ms |
18768 KB |
Output is correct |
18 |
Correct |
2433 ms |
18768 KB |
Output is correct |
19 |
Correct |
2386 ms |
18892 KB |
Output is correct |
20 |
Correct |
2017 ms |
18640 KB |
Output is correct |
21 |
Correct |
1785 ms |
18844 KB |
Output is correct |
22 |
Correct |
2028 ms |
18716 KB |
Output is correct |
23 |
Correct |
1670 ms |
18600 KB |
Output is correct |
24 |
Correct |
2517 ms |
18780 KB |
Output is correct |
25 |
Correct |
2457 ms |
18784 KB |
Output is correct |
26 |
Correct |
2463 ms |
18800 KB |
Output is correct |
27 |
Correct |
2477 ms |
19028 KB |
Output is correct |
28 |
Correct |
2445 ms |
18912 KB |
Output is correct |
29 |
Correct |
13 ms |
18512 KB |
Output is correct |
30 |
Correct |
13 ms |
18496 KB |
Output is correct |
31 |
Correct |
2433 ms |
18704 KB |
Output is correct |
32 |
Correct |
2421 ms |
18912 KB |
Output is correct |
33 |
Correct |
1240 ms |
18704 KB |
Output is correct |
34 |
Correct |
620 ms |
18588 KB |
Output is correct |
35 |
Correct |
20 ms |
18572 KB |
Output is correct |
36 |
Correct |
2418 ms |
18900 KB |
Output is correct |
37 |
Correct |
2441 ms |
18768 KB |
Output is correct |
38 |
Correct |
2424 ms |
18780 KB |
Output is correct |
39 |
Correct |
1759 ms |
18660 KB |
Output is correct |
40 |
Correct |
1234 ms |
18724 KB |
Output is correct |
41 |
Correct |
894 ms |
18572 KB |
Output is correct |
42 |
Correct |
115 ms |
18556 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3062 ms |
21264 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3062 ms |
21264 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
18528 KB |
Output is correct |
2 |
Correct |
659 ms |
18660 KB |
Output is correct |
3 |
Correct |
1281 ms |
18796 KB |
Output is correct |
4 |
Correct |
1280 ms |
18672 KB |
Output is correct |
5 |
Correct |
1260 ms |
18676 KB |
Output is correct |
6 |
Correct |
1808 ms |
18600 KB |
Output is correct |
7 |
Correct |
2426 ms |
18588 KB |
Output is correct |
8 |
Correct |
2393 ms |
18604 KB |
Output is correct |
9 |
Correct |
2390 ms |
18768 KB |
Output is correct |
10 |
Correct |
2433 ms |
18768 KB |
Output is correct |
11 |
Correct |
2386 ms |
18892 KB |
Output is correct |
12 |
Correct |
2017 ms |
18640 KB |
Output is correct |
13 |
Execution timed out |
3062 ms |
21264 KB |
Time limit exceeded |
14 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
18512 KB |
Output is correct |
2 |
Correct |
13 ms |
18512 KB |
Output is correct |
3 |
Correct |
13 ms |
18512 KB |
Output is correct |
4 |
Correct |
14 ms |
18512 KB |
Output is correct |
5 |
Correct |
12 ms |
18512 KB |
Output is correct |
6 |
Correct |
14 ms |
18608 KB |
Output is correct |
7 |
Correct |
12 ms |
18512 KB |
Output is correct |
8 |
Correct |
12 ms |
18512 KB |
Output is correct |
9 |
Correct |
13 ms |
18528 KB |
Output is correct |
10 |
Correct |
659 ms |
18660 KB |
Output is correct |
11 |
Correct |
1281 ms |
18796 KB |
Output is correct |
12 |
Correct |
1280 ms |
18672 KB |
Output is correct |
13 |
Correct |
1260 ms |
18676 KB |
Output is correct |
14 |
Correct |
1808 ms |
18600 KB |
Output is correct |
15 |
Correct |
2426 ms |
18588 KB |
Output is correct |
16 |
Correct |
2393 ms |
18604 KB |
Output is correct |
17 |
Correct |
2390 ms |
18768 KB |
Output is correct |
18 |
Correct |
2433 ms |
18768 KB |
Output is correct |
19 |
Correct |
2386 ms |
18892 KB |
Output is correct |
20 |
Correct |
2017 ms |
18640 KB |
Output is correct |
21 |
Correct |
1785 ms |
18844 KB |
Output is correct |
22 |
Correct |
2028 ms |
18716 KB |
Output is correct |
23 |
Correct |
1670 ms |
18600 KB |
Output is correct |
24 |
Correct |
2517 ms |
18780 KB |
Output is correct |
25 |
Correct |
2457 ms |
18784 KB |
Output is correct |
26 |
Correct |
2463 ms |
18800 KB |
Output is correct |
27 |
Correct |
2477 ms |
19028 KB |
Output is correct |
28 |
Correct |
2445 ms |
18912 KB |
Output is correct |
29 |
Correct |
13 ms |
18512 KB |
Output is correct |
30 |
Correct |
13 ms |
18496 KB |
Output is correct |
31 |
Correct |
2433 ms |
18704 KB |
Output is correct |
32 |
Correct |
2421 ms |
18912 KB |
Output is correct |
33 |
Correct |
1240 ms |
18704 KB |
Output is correct |
34 |
Correct |
620 ms |
18588 KB |
Output is correct |
35 |
Correct |
20 ms |
18572 KB |
Output is correct |
36 |
Correct |
2418 ms |
18900 KB |
Output is correct |
37 |
Correct |
2441 ms |
18768 KB |
Output is correct |
38 |
Correct |
2424 ms |
18780 KB |
Output is correct |
39 |
Correct |
1759 ms |
18660 KB |
Output is correct |
40 |
Correct |
1234 ms |
18724 KB |
Output is correct |
41 |
Correct |
894 ms |
18572 KB |
Output is correct |
42 |
Correct |
115 ms |
18556 KB |
Output is correct |
43 |
Execution timed out |
3029 ms |
19156 KB |
Time limit exceeded |
44 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
18512 KB |
Output is correct |
2 |
Correct |
13 ms |
18512 KB |
Output is correct |
3 |
Correct |
13 ms |
18512 KB |
Output is correct |
4 |
Correct |
14 ms |
18512 KB |
Output is correct |
5 |
Correct |
12 ms |
18512 KB |
Output is correct |
6 |
Correct |
14 ms |
18608 KB |
Output is correct |
7 |
Correct |
12 ms |
18512 KB |
Output is correct |
8 |
Correct |
12 ms |
18512 KB |
Output is correct |
9 |
Correct |
13 ms |
18528 KB |
Output is correct |
10 |
Correct |
659 ms |
18660 KB |
Output is correct |
11 |
Correct |
1281 ms |
18796 KB |
Output is correct |
12 |
Correct |
1280 ms |
18672 KB |
Output is correct |
13 |
Correct |
1260 ms |
18676 KB |
Output is correct |
14 |
Correct |
1808 ms |
18600 KB |
Output is correct |
15 |
Correct |
2426 ms |
18588 KB |
Output is correct |
16 |
Correct |
2393 ms |
18604 KB |
Output is correct |
17 |
Correct |
2390 ms |
18768 KB |
Output is correct |
18 |
Correct |
2433 ms |
18768 KB |
Output is correct |
19 |
Correct |
2386 ms |
18892 KB |
Output is correct |
20 |
Correct |
2017 ms |
18640 KB |
Output is correct |
21 |
Correct |
1785 ms |
18844 KB |
Output is correct |
22 |
Correct |
2028 ms |
18716 KB |
Output is correct |
23 |
Correct |
1670 ms |
18600 KB |
Output is correct |
24 |
Correct |
2517 ms |
18780 KB |
Output is correct |
25 |
Correct |
2457 ms |
18784 KB |
Output is correct |
26 |
Correct |
2463 ms |
18800 KB |
Output is correct |
27 |
Correct |
2477 ms |
19028 KB |
Output is correct |
28 |
Correct |
2445 ms |
18912 KB |
Output is correct |
29 |
Correct |
13 ms |
18512 KB |
Output is correct |
30 |
Correct |
13 ms |
18496 KB |
Output is correct |
31 |
Correct |
2433 ms |
18704 KB |
Output is correct |
32 |
Correct |
2421 ms |
18912 KB |
Output is correct |
33 |
Correct |
1240 ms |
18704 KB |
Output is correct |
34 |
Correct |
620 ms |
18588 KB |
Output is correct |
35 |
Correct |
20 ms |
18572 KB |
Output is correct |
36 |
Correct |
2418 ms |
18900 KB |
Output is correct |
37 |
Correct |
2441 ms |
18768 KB |
Output is correct |
38 |
Correct |
2424 ms |
18780 KB |
Output is correct |
39 |
Correct |
1759 ms |
18660 KB |
Output is correct |
40 |
Correct |
1234 ms |
18724 KB |
Output is correct |
41 |
Correct |
894 ms |
18572 KB |
Output is correct |
42 |
Correct |
115 ms |
18556 KB |
Output is correct |
43 |
Execution timed out |
3062 ms |
21264 KB |
Time limit exceeded |
44 |
Halted |
0 ms |
0 KB |
- |