#include "circuit.h"
#include<bits/stdc++.h>
using namespace std;
const long long MOD=1e9+2022;
//const int INF = INT_MAX;
vector<vector<int> > adi;
vector<int> par;
vector<int> state;
vector<vector<long long> > pos;
void update_node(int v){
int s=adi[v].size()+1;
vector<long long> cnt(s);
cnt[0] = 1;
for(auto u: adi[v]){
for(int i=s-1; i>=0; i--){
cnt[i] *= pos[u][0];
cnt[i]%=MOD;
if(0<i){
long long add = cnt[i-1]*pos[u][1];
add%=MOD;
cnt[i] += add;
cnt[i]%=MOD;
}
}
}
long long ssum=0ll;
pos[v][1]=0ll;
for(int i=s-1; i>=1; i--){
ssum += cnt[i];
ssum%=MOD;
pos[v][1] += ssum;
pos[v][1] %= MOD;
}
ssum=cnt[0];
pos[v][0]=0ll;
for(int i=1; i<s; i++){
pos[v][0] += ssum;
pos[v][0] %= MOD;
ssum += cnt[i];
ssum %= MOD;
}
}
void init(int n, int m, vector<int> p, vector<int> a) {
par = p;
state.assign(n+m, 0);
for(int i=0; i<m; i++){
state[n+i] = a[i];
}
adi.assign(n, {});
for(int i=1; i<n+m; i++){
adi[p[i]].push_back(i);
}
pos.assign(n+m, vector<long long> (2, 0));
for(int i=n; i<n+m; i++){
pos[i][state[i]] = 1;
}
for(int i=n-1; i>=0; i--){
update_node(i);
}
}
int count_ways(int L, int R) {
priority_queue<int> pq;
for(int i=L; i<=R; i++){
state[i] = 1-state[i];
pos[i][state[i]] = 1;
pos[i][1-state[i]] = 0;
pq.push(par[i]);
}
set<int> done;
while(!pq.empty()){
int v=pq.top();
pq.pop();
if(done.find(v)!=done.end()) continue;
done.insert(v);
update_node(v);
if(par[v]!=-1){
pq.push(par[v]);
}
}
return pos[0][1];
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
19 ms |
336 KB |
Output is correct |
4 |
Correct |
20 ms |
336 KB |
Output is correct |
5 |
Correct |
20 ms |
336 KB |
Output is correct |
6 |
Correct |
20 ms |
384 KB |
Output is correct |
7 |
Correct |
20 ms |
336 KB |
Output is correct |
8 |
Correct |
20 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
464 KB |
Output is correct |
8 |
Correct |
1 ms |
464 KB |
Output is correct |
9 |
Correct |
2 ms |
464 KB |
Output is correct |
10 |
Correct |
2 ms |
464 KB |
Output is correct |
11 |
Correct |
2 ms |
464 KB |
Output is correct |
12 |
Correct |
2 ms |
464 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
19 ms |
336 KB |
Output is correct |
4 |
Correct |
20 ms |
336 KB |
Output is correct |
5 |
Correct |
20 ms |
336 KB |
Output is correct |
6 |
Correct |
20 ms |
384 KB |
Output is correct |
7 |
Correct |
20 ms |
336 KB |
Output is correct |
8 |
Correct |
20 ms |
336 KB |
Output is correct |
9 |
Correct |
0 ms |
208 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
464 KB |
Output is correct |
16 |
Correct |
1 ms |
464 KB |
Output is correct |
17 |
Correct |
2 ms |
464 KB |
Output is correct |
18 |
Correct |
2 ms |
464 KB |
Output is correct |
19 |
Correct |
2 ms |
464 KB |
Output is correct |
20 |
Correct |
2 ms |
464 KB |
Output is correct |
21 |
Correct |
2 ms |
464 KB |
Output is correct |
22 |
Correct |
1 ms |
336 KB |
Output is correct |
23 |
Correct |
1 ms |
336 KB |
Output is correct |
24 |
Correct |
1 ms |
464 KB |
Output is correct |
25 |
Correct |
2 ms |
464 KB |
Output is correct |
26 |
Correct |
2 ms |
464 KB |
Output is correct |
27 |
Correct |
1 ms |
464 KB |
Output is correct |
28 |
Correct |
3 ms |
536 KB |
Output is correct |
29 |
Correct |
20 ms |
336 KB |
Output is correct |
30 |
Correct |
20 ms |
336 KB |
Output is correct |
31 |
Correct |
1 ms |
464 KB |
Output is correct |
32 |
Correct |
2 ms |
464 KB |
Output is correct |
33 |
Correct |
2 ms |
336 KB |
Output is correct |
34 |
Correct |
1 ms |
336 KB |
Output is correct |
35 |
Correct |
4 ms |
336 KB |
Output is correct |
36 |
Correct |
1 ms |
464 KB |
Output is correct |
37 |
Correct |
21 ms |
464 KB |
Output is correct |
38 |
Correct |
21 ms |
464 KB |
Output is correct |
39 |
Correct |
1 ms |
336 KB |
Output is correct |
40 |
Correct |
1 ms |
336 KB |
Output is correct |
41 |
Correct |
1 ms |
336 KB |
Output is correct |
42 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
624 ms |
6992 KB |
Output is correct |
2 |
Correct |
944 ms |
13640 KB |
Output is correct |
3 |
Correct |
973 ms |
13648 KB |
Output is correct |
4 |
Correct |
1014 ms |
13608 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
624 ms |
6992 KB |
Output is correct |
2 |
Correct |
944 ms |
13640 KB |
Output is correct |
3 |
Correct |
973 ms |
13648 KB |
Output is correct |
4 |
Correct |
1014 ms |
13608 KB |
Output is correct |
5 |
Execution timed out |
3089 ms |
8256 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
464 KB |
Output is correct |
8 |
Correct |
1 ms |
464 KB |
Output is correct |
9 |
Correct |
2 ms |
464 KB |
Output is correct |
10 |
Correct |
2 ms |
464 KB |
Output is correct |
11 |
Correct |
2 ms |
464 KB |
Output is correct |
12 |
Correct |
2 ms |
464 KB |
Output is correct |
13 |
Correct |
624 ms |
6992 KB |
Output is correct |
14 |
Correct |
944 ms |
13640 KB |
Output is correct |
15 |
Correct |
973 ms |
13648 KB |
Output is correct |
16 |
Correct |
1014 ms |
13608 KB |
Output is correct |
17 |
Execution timed out |
3089 ms |
8256 KB |
Time limit exceeded |
18 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
19 ms |
336 KB |
Output is correct |
4 |
Correct |
20 ms |
336 KB |
Output is correct |
5 |
Correct |
20 ms |
336 KB |
Output is correct |
6 |
Correct |
20 ms |
384 KB |
Output is correct |
7 |
Correct |
20 ms |
336 KB |
Output is correct |
8 |
Correct |
20 ms |
336 KB |
Output is correct |
9 |
Correct |
0 ms |
208 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
464 KB |
Output is correct |
16 |
Correct |
1 ms |
464 KB |
Output is correct |
17 |
Correct |
2 ms |
464 KB |
Output is correct |
18 |
Correct |
2 ms |
464 KB |
Output is correct |
19 |
Correct |
2 ms |
464 KB |
Output is correct |
20 |
Correct |
2 ms |
464 KB |
Output is correct |
21 |
Correct |
2 ms |
464 KB |
Output is correct |
22 |
Correct |
1 ms |
336 KB |
Output is correct |
23 |
Correct |
1 ms |
336 KB |
Output is correct |
24 |
Correct |
1 ms |
464 KB |
Output is correct |
25 |
Correct |
2 ms |
464 KB |
Output is correct |
26 |
Correct |
2 ms |
464 KB |
Output is correct |
27 |
Correct |
1 ms |
464 KB |
Output is correct |
28 |
Correct |
3 ms |
536 KB |
Output is correct |
29 |
Correct |
20 ms |
336 KB |
Output is correct |
30 |
Correct |
20 ms |
336 KB |
Output is correct |
31 |
Correct |
1 ms |
464 KB |
Output is correct |
32 |
Correct |
2 ms |
464 KB |
Output is correct |
33 |
Correct |
2 ms |
336 KB |
Output is correct |
34 |
Correct |
1 ms |
336 KB |
Output is correct |
35 |
Correct |
4 ms |
336 KB |
Output is correct |
36 |
Correct |
1 ms |
464 KB |
Output is correct |
37 |
Correct |
21 ms |
464 KB |
Output is correct |
38 |
Correct |
21 ms |
464 KB |
Output is correct |
39 |
Correct |
1 ms |
336 KB |
Output is correct |
40 |
Correct |
1 ms |
336 KB |
Output is correct |
41 |
Correct |
1 ms |
336 KB |
Output is correct |
42 |
Correct |
1 ms |
336 KB |
Output is correct |
43 |
Execution timed out |
3043 ms |
1008 KB |
Time limit exceeded |
44 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
19 ms |
336 KB |
Output is correct |
4 |
Correct |
20 ms |
336 KB |
Output is correct |
5 |
Correct |
20 ms |
336 KB |
Output is correct |
6 |
Correct |
20 ms |
384 KB |
Output is correct |
7 |
Correct |
20 ms |
336 KB |
Output is correct |
8 |
Correct |
20 ms |
336 KB |
Output is correct |
9 |
Correct |
0 ms |
208 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
464 KB |
Output is correct |
16 |
Correct |
1 ms |
464 KB |
Output is correct |
17 |
Correct |
2 ms |
464 KB |
Output is correct |
18 |
Correct |
2 ms |
464 KB |
Output is correct |
19 |
Correct |
2 ms |
464 KB |
Output is correct |
20 |
Correct |
2 ms |
464 KB |
Output is correct |
21 |
Correct |
2 ms |
464 KB |
Output is correct |
22 |
Correct |
1 ms |
336 KB |
Output is correct |
23 |
Correct |
1 ms |
336 KB |
Output is correct |
24 |
Correct |
1 ms |
464 KB |
Output is correct |
25 |
Correct |
2 ms |
464 KB |
Output is correct |
26 |
Correct |
2 ms |
464 KB |
Output is correct |
27 |
Correct |
1 ms |
464 KB |
Output is correct |
28 |
Correct |
3 ms |
536 KB |
Output is correct |
29 |
Correct |
20 ms |
336 KB |
Output is correct |
30 |
Correct |
20 ms |
336 KB |
Output is correct |
31 |
Correct |
1 ms |
464 KB |
Output is correct |
32 |
Correct |
2 ms |
464 KB |
Output is correct |
33 |
Correct |
2 ms |
336 KB |
Output is correct |
34 |
Correct |
1 ms |
336 KB |
Output is correct |
35 |
Correct |
4 ms |
336 KB |
Output is correct |
36 |
Correct |
1 ms |
464 KB |
Output is correct |
37 |
Correct |
21 ms |
464 KB |
Output is correct |
38 |
Correct |
21 ms |
464 KB |
Output is correct |
39 |
Correct |
1 ms |
336 KB |
Output is correct |
40 |
Correct |
1 ms |
336 KB |
Output is correct |
41 |
Correct |
1 ms |
336 KB |
Output is correct |
42 |
Correct |
1 ms |
336 KB |
Output is correct |
43 |
Correct |
624 ms |
6992 KB |
Output is correct |
44 |
Correct |
944 ms |
13640 KB |
Output is correct |
45 |
Correct |
973 ms |
13648 KB |
Output is correct |
46 |
Correct |
1014 ms |
13608 KB |
Output is correct |
47 |
Execution timed out |
3089 ms |
8256 KB |
Time limit exceeded |
48 |
Halted |
0 ms |
0 KB |
- |