#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];
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);
}
}
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)
{
for(int i=l;i<=r;i++) swap(seg[i+pot-1][0],seg[i+pot-1][1]);
ll ans=0;
for(int i=n;i<n+m;i++) ans+=seg[i+pot-1][1];
return ans%mod;
}
/*int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
init(3, 4, {-1, 0, 1, 2, 1, 1, 0}, {1, 0, 1, 0});
cout<<count_ways(3, 4)<<endl;
cout<<count_ways(4, 5)<<endl;
cout<<count_ways(3, 6)<<endl;
return 0;
}*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
14288 KB |
Output is correct |
2 |
Correct |
8 ms |
14464 KB |
Output is correct |
3 |
Correct |
8 ms |
14416 KB |
Output is correct |
4 |
Correct |
8 ms |
14380 KB |
Output is correct |
5 |
Correct |
8 ms |
14416 KB |
Output is correct |
6 |
Correct |
7 ms |
14416 KB |
Output is correct |
7 |
Correct |
7 ms |
14416 KB |
Output is correct |
8 |
Correct |
8 ms |
14416 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
14288 KB |
Output is correct |
2 |
Correct |
7 ms |
14380 KB |
Output is correct |
3 |
Correct |
8 ms |
14416 KB |
Output is correct |
4 |
Correct |
9 ms |
14416 KB |
Output is correct |
5 |
Correct |
8 ms |
14416 KB |
Output is correct |
6 |
Correct |
8 ms |
14544 KB |
Output is correct |
7 |
Correct |
8 ms |
14544 KB |
Output is correct |
8 |
Correct |
8 ms |
14540 KB |
Output is correct |
9 |
Correct |
9 ms |
14580 KB |
Output is correct |
10 |
Correct |
9 ms |
14672 KB |
Output is correct |
11 |
Correct |
8 ms |
14612 KB |
Output is correct |
12 |
Correct |
8 ms |
14544 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
14288 KB |
Output is correct |
2 |
Correct |
8 ms |
14464 KB |
Output is correct |
3 |
Correct |
8 ms |
14416 KB |
Output is correct |
4 |
Correct |
8 ms |
14380 KB |
Output is correct |
5 |
Correct |
8 ms |
14416 KB |
Output is correct |
6 |
Correct |
7 ms |
14416 KB |
Output is correct |
7 |
Correct |
7 ms |
14416 KB |
Output is correct |
8 |
Correct |
8 ms |
14416 KB |
Output is correct |
9 |
Correct |
7 ms |
14288 KB |
Output is correct |
10 |
Correct |
7 ms |
14380 KB |
Output is correct |
11 |
Correct |
8 ms |
14416 KB |
Output is correct |
12 |
Correct |
9 ms |
14416 KB |
Output is correct |
13 |
Correct |
8 ms |
14416 KB |
Output is correct |
14 |
Correct |
8 ms |
14544 KB |
Output is correct |
15 |
Correct |
8 ms |
14544 KB |
Output is correct |
16 |
Correct |
8 ms |
14540 KB |
Output is correct |
17 |
Correct |
9 ms |
14580 KB |
Output is correct |
18 |
Correct |
9 ms |
14672 KB |
Output is correct |
19 |
Correct |
8 ms |
14612 KB |
Output is correct |
20 |
Correct |
8 ms |
14544 KB |
Output is correct |
21 |
Correct |
8 ms |
14544 KB |
Output is correct |
22 |
Correct |
8 ms |
14416 KB |
Output is correct |
23 |
Correct |
8 ms |
14416 KB |
Output is correct |
24 |
Correct |
8 ms |
14544 KB |
Output is correct |
25 |
Correct |
9 ms |
14544 KB |
Output is correct |
26 |
Correct |
8 ms |
14544 KB |
Output is correct |
27 |
Correct |
8 ms |
14544 KB |
Output is correct |
28 |
Correct |
9 ms |
14476 KB |
Output is correct |
29 |
Correct |
8 ms |
14416 KB |
Output is correct |
30 |
Correct |
10 ms |
14416 KB |
Output is correct |
31 |
Correct |
8 ms |
14544 KB |
Output is correct |
32 |
Correct |
8 ms |
14544 KB |
Output is correct |
33 |
Correct |
10 ms |
14488 KB |
Output is correct |
34 |
Correct |
8 ms |
14416 KB |
Output is correct |
35 |
Correct |
8 ms |
14348 KB |
Output is correct |
36 |
Correct |
8 ms |
14672 KB |
Output is correct |
37 |
Correct |
10 ms |
14548 KB |
Output is correct |
38 |
Correct |
8 ms |
14672 KB |
Output is correct |
39 |
Correct |
8 ms |
14504 KB |
Output is correct |
40 |
Correct |
8 ms |
14416 KB |
Output is correct |
41 |
Correct |
8 ms |
14484 KB |
Output is correct |
42 |
Correct |
8 ms |
14384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2683 ms |
20292 KB |
Output is correct |
2 |
Execution timed out |
3084 ms |
26184 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2683 ms |
20292 KB |
Output is correct |
2 |
Execution timed out |
3084 ms |
26184 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
14288 KB |
Output is correct |
2 |
Correct |
7 ms |
14380 KB |
Output is correct |
3 |
Correct |
8 ms |
14416 KB |
Output is correct |
4 |
Correct |
9 ms |
14416 KB |
Output is correct |
5 |
Correct |
8 ms |
14416 KB |
Output is correct |
6 |
Correct |
8 ms |
14544 KB |
Output is correct |
7 |
Correct |
8 ms |
14544 KB |
Output is correct |
8 |
Correct |
8 ms |
14540 KB |
Output is correct |
9 |
Correct |
9 ms |
14580 KB |
Output is correct |
10 |
Correct |
9 ms |
14672 KB |
Output is correct |
11 |
Correct |
8 ms |
14612 KB |
Output is correct |
12 |
Correct |
8 ms |
14544 KB |
Output is correct |
13 |
Correct |
2683 ms |
20292 KB |
Output is correct |
14 |
Execution timed out |
3084 ms |
26184 KB |
Time limit exceeded |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
14288 KB |
Output is correct |
2 |
Correct |
8 ms |
14464 KB |
Output is correct |
3 |
Correct |
8 ms |
14416 KB |
Output is correct |
4 |
Correct |
8 ms |
14380 KB |
Output is correct |
5 |
Correct |
8 ms |
14416 KB |
Output is correct |
6 |
Correct |
7 ms |
14416 KB |
Output is correct |
7 |
Correct |
7 ms |
14416 KB |
Output is correct |
8 |
Correct |
8 ms |
14416 KB |
Output is correct |
9 |
Correct |
7 ms |
14288 KB |
Output is correct |
10 |
Correct |
7 ms |
14380 KB |
Output is correct |
11 |
Correct |
8 ms |
14416 KB |
Output is correct |
12 |
Correct |
9 ms |
14416 KB |
Output is correct |
13 |
Correct |
8 ms |
14416 KB |
Output is correct |
14 |
Correct |
8 ms |
14544 KB |
Output is correct |
15 |
Correct |
8 ms |
14544 KB |
Output is correct |
16 |
Correct |
8 ms |
14540 KB |
Output is correct |
17 |
Correct |
9 ms |
14580 KB |
Output is correct |
18 |
Correct |
9 ms |
14672 KB |
Output is correct |
19 |
Correct |
8 ms |
14612 KB |
Output is correct |
20 |
Correct |
8 ms |
14544 KB |
Output is correct |
21 |
Correct |
8 ms |
14544 KB |
Output is correct |
22 |
Correct |
8 ms |
14416 KB |
Output is correct |
23 |
Correct |
8 ms |
14416 KB |
Output is correct |
24 |
Correct |
8 ms |
14544 KB |
Output is correct |
25 |
Correct |
9 ms |
14544 KB |
Output is correct |
26 |
Correct |
8 ms |
14544 KB |
Output is correct |
27 |
Correct |
8 ms |
14544 KB |
Output is correct |
28 |
Correct |
9 ms |
14476 KB |
Output is correct |
29 |
Correct |
8 ms |
14416 KB |
Output is correct |
30 |
Correct |
10 ms |
14416 KB |
Output is correct |
31 |
Correct |
8 ms |
14544 KB |
Output is correct |
32 |
Correct |
8 ms |
14544 KB |
Output is correct |
33 |
Correct |
10 ms |
14488 KB |
Output is correct |
34 |
Correct |
8 ms |
14416 KB |
Output is correct |
35 |
Correct |
8 ms |
14348 KB |
Output is correct |
36 |
Correct |
8 ms |
14672 KB |
Output is correct |
37 |
Correct |
10 ms |
14548 KB |
Output is correct |
38 |
Correct |
8 ms |
14672 KB |
Output is correct |
39 |
Correct |
8 ms |
14504 KB |
Output is correct |
40 |
Correct |
8 ms |
14416 KB |
Output is correct |
41 |
Correct |
8 ms |
14484 KB |
Output is correct |
42 |
Correct |
8 ms |
14384 KB |
Output is correct |
43 |
Correct |
812 ms |
14800 KB |
Output is correct |
44 |
Correct |
1183 ms |
15036 KB |
Output is correct |
45 |
Correct |
1200 ms |
14928 KB |
Output is correct |
46 |
Correct |
1170 ms |
15164 KB |
Output is correct |
47 |
Correct |
1394 ms |
15168 KB |
Output is correct |
48 |
Correct |
1423 ms |
15184 KB |
Output is correct |
49 |
Correct |
1339 ms |
15168 KB |
Output is correct |
50 |
Correct |
1736 ms |
15184 KB |
Output is correct |
51 |
Correct |
2043 ms |
14724 KB |
Output is correct |
52 |
Correct |
1786 ms |
14732 KB |
Output is correct |
53 |
Correct |
760 ms |
15424 KB |
Output is correct |
54 |
Correct |
2040 ms |
15360 KB |
Output is correct |
55 |
Correct |
1837 ms |
14908 KB |
Output is correct |
56 |
Correct |
1873 ms |
14828 KB |
Output is correct |
57 |
Correct |
1946 ms |
14672 KB |
Output is correct |
58 |
Correct |
1745 ms |
15696 KB |
Output is correct |
59 |
Correct |
1813 ms |
15740 KB |
Output is correct |
60 |
Correct |
2098 ms |
15808 KB |
Output is correct |
61 |
Correct |
1426 ms |
15104 KB |
Output is correct |
62 |
Correct |
1448 ms |
14800 KB |
Output is correct |
63 |
Correct |
1417 ms |
14652 KB |
Output is correct |
64 |
Correct |
1535 ms |
14660 KB |
Output is correct |
65 |
Correct |
552 ms |
14780 KB |
Output is correct |
66 |
Correct |
1480 ms |
15032 KB |
Output is correct |
67 |
Correct |
1460 ms |
15028 KB |
Output is correct |
68 |
Correct |
1808 ms |
15124 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
14288 KB |
Output is correct |
2 |
Correct |
8 ms |
14464 KB |
Output is correct |
3 |
Correct |
8 ms |
14416 KB |
Output is correct |
4 |
Correct |
8 ms |
14380 KB |
Output is correct |
5 |
Correct |
8 ms |
14416 KB |
Output is correct |
6 |
Correct |
7 ms |
14416 KB |
Output is correct |
7 |
Correct |
7 ms |
14416 KB |
Output is correct |
8 |
Correct |
8 ms |
14416 KB |
Output is correct |
9 |
Correct |
7 ms |
14288 KB |
Output is correct |
10 |
Correct |
7 ms |
14380 KB |
Output is correct |
11 |
Correct |
8 ms |
14416 KB |
Output is correct |
12 |
Correct |
9 ms |
14416 KB |
Output is correct |
13 |
Correct |
8 ms |
14416 KB |
Output is correct |
14 |
Correct |
8 ms |
14544 KB |
Output is correct |
15 |
Correct |
8 ms |
14544 KB |
Output is correct |
16 |
Correct |
8 ms |
14540 KB |
Output is correct |
17 |
Correct |
9 ms |
14580 KB |
Output is correct |
18 |
Correct |
9 ms |
14672 KB |
Output is correct |
19 |
Correct |
8 ms |
14612 KB |
Output is correct |
20 |
Correct |
8 ms |
14544 KB |
Output is correct |
21 |
Correct |
8 ms |
14544 KB |
Output is correct |
22 |
Correct |
8 ms |
14416 KB |
Output is correct |
23 |
Correct |
8 ms |
14416 KB |
Output is correct |
24 |
Correct |
8 ms |
14544 KB |
Output is correct |
25 |
Correct |
9 ms |
14544 KB |
Output is correct |
26 |
Correct |
8 ms |
14544 KB |
Output is correct |
27 |
Correct |
8 ms |
14544 KB |
Output is correct |
28 |
Correct |
9 ms |
14476 KB |
Output is correct |
29 |
Correct |
8 ms |
14416 KB |
Output is correct |
30 |
Correct |
10 ms |
14416 KB |
Output is correct |
31 |
Correct |
8 ms |
14544 KB |
Output is correct |
32 |
Correct |
8 ms |
14544 KB |
Output is correct |
33 |
Correct |
10 ms |
14488 KB |
Output is correct |
34 |
Correct |
8 ms |
14416 KB |
Output is correct |
35 |
Correct |
8 ms |
14348 KB |
Output is correct |
36 |
Correct |
8 ms |
14672 KB |
Output is correct |
37 |
Correct |
10 ms |
14548 KB |
Output is correct |
38 |
Correct |
8 ms |
14672 KB |
Output is correct |
39 |
Correct |
8 ms |
14504 KB |
Output is correct |
40 |
Correct |
8 ms |
14416 KB |
Output is correct |
41 |
Correct |
8 ms |
14484 KB |
Output is correct |
42 |
Correct |
8 ms |
14384 KB |
Output is correct |
43 |
Correct |
2683 ms |
20292 KB |
Output is correct |
44 |
Execution timed out |
3084 ms |
26184 KB |
Time limit exceeded |
45 |
Halted |
0 ms |
0 KB |
- |