#include <bits/stdc++.h>
#define pb push_back
#define f first
#define sc second
using namespace std;
typedef long long int ll;
typedef string str;
const ll md = 1000002022;
struct segtree{
struct node{
ll x = 0, sum = 0;
bool rev = 0;
node(){
}
node operator+(node X){
node rt;
rt.sum = (sum+X.sum)%md;
rt.x = (x+X.x)%md;
return rt;
}
void pushdown(node &X){
if(!rev) return;
X.rev^=rev;
X.x = (X.sum-X.x)%md;
}
};
int k;
vector<node> v;
segtree(const vector<ll>& sum){
int n = sum.size();
k = 1;
while(k < n) k*=2;
v.resize(2*k, node());
for(int i = k; i < k+n; i++) v[i].sum = sum[i-k];
for(int i = k-1; i > 0; i--) v[i] = v[2*i]+v[2*i+1];
}
void update(int l, int r, int nd, int a, int b){
if(a > r || b < l) return;
if(a >= l && b <= r){
v[nd].rev^=1;
v[nd].x = v[nd].sum-v[nd].x;
return;
}
int mid = (a+b)/2;
v[nd].pushdown(v[2*nd]);
v[nd].pushdown(v[2*nd+1]);
v[nd].rev = 0;
update(l, r, 2*nd, a, mid);
update(l, r, 2*nd+1, mid+1, b);
v[nd] = v[2*nd]+v[2*nd+1];
}
void update(int l, int r){
update(l, r, 1, 0, k-1);
}
int get(){
if(v[1].x < 0) v[1].x+=md;
return v[1].x;
}
};
int n, m;
vector<int> P, A;
vector<vector<int>> tree;
vector<ll> options, coefficient;
segtree s({});
void dfs(int nd){
if(nd >= n) return;
options[nd] = tree[nd].size();
for(int x: tree[nd]) dfs(x), options[nd]*=options[x], options[nd]%=md;
}
void dfs2(int nd, ll coeff){
if(nd >= n){
coefficient[nd-n] = coeff;
return;
}
for(int x: tree[nd]){
ll _coeff = coeff;
for(int y: tree[nd]) if(y != x) _coeff*=options[y], _coeff%=md;
dfs2(x, _coeff);
}
}
void init(int _n, int _m, vector<int> _P, vector<int> _A){
swap(n, _n), swap(m, _m), swap(P, _P), swap(A, _A);
tree.resize(n+m);
for(int i = 1; i < n+m; i++) tree[P[i]].pb(i);
options.assign(n+m, 1);
coefficient.resize(m);
dfs(0);
dfs2(0, 1);
s = segtree(coefficient);
for(int i = 0; i < m; i++) if(A[i]) s.update(i, i);
}
int count_ways(int L, int R){
s.update(L-n, R-n);
return s.get();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
5 ms |
336 KB |
Output is correct |
4 |
Correct |
5 ms |
336 KB |
Output is correct |
5 |
Correct |
6 ms |
356 KB |
Output is correct |
6 |
Correct |
5 ms |
336 KB |
Output is correct |
7 |
Correct |
6 ms |
336 KB |
Output is correct |
8 |
Correct |
5 ms |
336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 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 |
1 ms |
464 KB |
Output is correct |
10 |
Correct |
1 ms |
464 KB |
Output is correct |
11 |
Correct |
1 ms |
464 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
5 ms |
336 KB |
Output is correct |
4 |
Correct |
5 ms |
336 KB |
Output is correct |
5 |
Correct |
6 ms |
356 KB |
Output is correct |
6 |
Correct |
5 ms |
336 KB |
Output is correct |
7 |
Correct |
6 ms |
336 KB |
Output is correct |
8 |
Correct |
5 ms |
336 KB |
Output is correct |
9 |
Correct |
0 ms |
208 KB |
Output is correct |
10 |
Correct |
0 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 |
1 ms |
464 KB |
Output is correct |
18 |
Correct |
1 ms |
464 KB |
Output is correct |
19 |
Correct |
1 ms |
464 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
1 ms |
336 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 |
1 ms |
464 KB |
Output is correct |
26 |
Correct |
1 ms |
464 KB |
Output is correct |
27 |
Correct |
1 ms |
464 KB |
Output is correct |
28 |
Correct |
1 ms |
464 KB |
Output is correct |
29 |
Correct |
5 ms |
336 KB |
Output is correct |
30 |
Correct |
5 ms |
336 KB |
Output is correct |
31 |
Correct |
1 ms |
384 KB |
Output is correct |
32 |
Correct |
1 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 |
1 ms |
336 KB |
Output is correct |
36 |
Correct |
1 ms |
464 KB |
Output is correct |
37 |
Correct |
6 ms |
464 KB |
Output is correct |
38 |
Correct |
5 ms |
536 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 |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
613 ms |
5956 KB |
Output is correct |
2 |
Correct |
733 ms |
11604 KB |
Output is correct |
3 |
Correct |
857 ms |
11684 KB |
Output is correct |
4 |
Correct |
847 ms |
11608 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
613 ms |
5956 KB |
Output is correct |
2 |
Correct |
733 ms |
11604 KB |
Output is correct |
3 |
Correct |
857 ms |
11684 KB |
Output is correct |
4 |
Correct |
847 ms |
11608 KB |
Output is correct |
5 |
Correct |
718 ms |
5968 KB |
Output is correct |
6 |
Correct |
833 ms |
11608 KB |
Output is correct |
7 |
Correct |
742 ms |
11608 KB |
Output is correct |
8 |
Correct |
848 ms |
11608 KB |
Output is correct |
9 |
Correct |
394 ms |
592 KB |
Output is correct |
10 |
Correct |
972 ms |
1004 KB |
Output is correct |
11 |
Correct |
710 ms |
1000 KB |
Output is correct |
12 |
Correct |
709 ms |
1004 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 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 |
1 ms |
464 KB |
Output is correct |
10 |
Correct |
1 ms |
464 KB |
Output is correct |
11 |
Correct |
1 ms |
464 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
613 ms |
5956 KB |
Output is correct |
14 |
Correct |
733 ms |
11604 KB |
Output is correct |
15 |
Correct |
857 ms |
11684 KB |
Output is correct |
16 |
Correct |
847 ms |
11608 KB |
Output is correct |
17 |
Correct |
718 ms |
5968 KB |
Output is correct |
18 |
Correct |
833 ms |
11608 KB |
Output is correct |
19 |
Correct |
742 ms |
11608 KB |
Output is correct |
20 |
Correct |
848 ms |
11608 KB |
Output is correct |
21 |
Correct |
394 ms |
592 KB |
Output is correct |
22 |
Correct |
972 ms |
1004 KB |
Output is correct |
23 |
Correct |
710 ms |
1000 KB |
Output is correct |
24 |
Correct |
709 ms |
1004 KB |
Output is correct |
25 |
Correct |
970 ms |
18844 KB |
Output is correct |
26 |
Correct |
1088 ms |
18992 KB |
Output is correct |
27 |
Correct |
1065 ms |
18988 KB |
Output is correct |
28 |
Correct |
704 ms |
18980 KB |
Output is correct |
29 |
Correct |
872 ms |
25252 KB |
Output is correct |
30 |
Correct |
911 ms |
25244 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
5 ms |
336 KB |
Output is correct |
4 |
Correct |
5 ms |
336 KB |
Output is correct |
5 |
Correct |
6 ms |
356 KB |
Output is correct |
6 |
Correct |
5 ms |
336 KB |
Output is correct |
7 |
Correct |
6 ms |
336 KB |
Output is correct |
8 |
Correct |
5 ms |
336 KB |
Output is correct |
9 |
Correct |
0 ms |
208 KB |
Output is correct |
10 |
Correct |
0 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 |
1 ms |
464 KB |
Output is correct |
18 |
Correct |
1 ms |
464 KB |
Output is correct |
19 |
Correct |
1 ms |
464 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
1 ms |
336 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 |
1 ms |
464 KB |
Output is correct |
26 |
Correct |
1 ms |
464 KB |
Output is correct |
27 |
Correct |
1 ms |
464 KB |
Output is correct |
28 |
Correct |
1 ms |
464 KB |
Output is correct |
29 |
Correct |
5 ms |
336 KB |
Output is correct |
30 |
Correct |
5 ms |
336 KB |
Output is correct |
31 |
Correct |
1 ms |
384 KB |
Output is correct |
32 |
Correct |
1 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 |
1 ms |
336 KB |
Output is correct |
36 |
Correct |
1 ms |
464 KB |
Output is correct |
37 |
Correct |
6 ms |
464 KB |
Output is correct |
38 |
Correct |
5 ms |
536 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 |
340 KB |
Output is correct |
43 |
Correct |
617 ms |
856 KB |
Output is correct |
44 |
Correct |
917 ms |
920 KB |
Output is correct |
45 |
Correct |
817 ms |
884 KB |
Output is correct |
46 |
Correct |
926 ms |
1320 KB |
Output is correct |
47 |
Correct |
797 ms |
1328 KB |
Output is correct |
48 |
Correct |
846 ms |
1312 KB |
Output is correct |
49 |
Correct |
862 ms |
1316 KB |
Output is correct |
50 |
Correct |
906 ms |
1308 KB |
Output is correct |
51 |
Correct |
1036 ms |
980 KB |
Output is correct |
52 |
Correct |
864 ms |
996 KB |
Output is correct |
53 |
Correct |
842 ms |
936 KB |
Output is correct |
54 |
Correct |
1028 ms |
1316 KB |
Output is correct |
55 |
Correct |
948 ms |
1132 KB |
Output is correct |
56 |
Correct |
834 ms |
1096 KB |
Output is correct |
57 |
Correct |
687 ms |
944 KB |
Output is correct |
58 |
Correct |
748 ms |
1620 KB |
Output is correct |
59 |
Correct |
975 ms |
1668 KB |
Output is correct |
60 |
Correct |
1081 ms |
1664 KB |
Output is correct |
61 |
Correct |
990 ms |
976 KB |
Output is correct |
62 |
Correct |
749 ms |
832 KB |
Output is correct |
63 |
Correct |
875 ms |
720 KB |
Output is correct |
64 |
Correct |
856 ms |
976 KB |
Output is correct |
65 |
Correct |
498 ms |
640 KB |
Output is correct |
66 |
Correct |
714 ms |
1008 KB |
Output is correct |
67 |
Correct |
927 ms |
1000 KB |
Output is correct |
68 |
Correct |
841 ms |
1020 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
5 ms |
336 KB |
Output is correct |
4 |
Correct |
5 ms |
336 KB |
Output is correct |
5 |
Correct |
6 ms |
356 KB |
Output is correct |
6 |
Correct |
5 ms |
336 KB |
Output is correct |
7 |
Correct |
6 ms |
336 KB |
Output is correct |
8 |
Correct |
5 ms |
336 KB |
Output is correct |
9 |
Correct |
0 ms |
208 KB |
Output is correct |
10 |
Correct |
0 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 |
1 ms |
464 KB |
Output is correct |
18 |
Correct |
1 ms |
464 KB |
Output is correct |
19 |
Correct |
1 ms |
464 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
1 ms |
336 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 |
1 ms |
464 KB |
Output is correct |
26 |
Correct |
1 ms |
464 KB |
Output is correct |
27 |
Correct |
1 ms |
464 KB |
Output is correct |
28 |
Correct |
1 ms |
464 KB |
Output is correct |
29 |
Correct |
5 ms |
336 KB |
Output is correct |
30 |
Correct |
5 ms |
336 KB |
Output is correct |
31 |
Correct |
1 ms |
384 KB |
Output is correct |
32 |
Correct |
1 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 |
1 ms |
336 KB |
Output is correct |
36 |
Correct |
1 ms |
464 KB |
Output is correct |
37 |
Correct |
6 ms |
464 KB |
Output is correct |
38 |
Correct |
5 ms |
536 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 |
340 KB |
Output is correct |
43 |
Correct |
613 ms |
5956 KB |
Output is correct |
44 |
Correct |
733 ms |
11604 KB |
Output is correct |
45 |
Correct |
857 ms |
11684 KB |
Output is correct |
46 |
Correct |
847 ms |
11608 KB |
Output is correct |
47 |
Correct |
718 ms |
5968 KB |
Output is correct |
48 |
Correct |
833 ms |
11608 KB |
Output is correct |
49 |
Correct |
742 ms |
11608 KB |
Output is correct |
50 |
Correct |
848 ms |
11608 KB |
Output is correct |
51 |
Correct |
394 ms |
592 KB |
Output is correct |
52 |
Correct |
972 ms |
1004 KB |
Output is correct |
53 |
Correct |
710 ms |
1000 KB |
Output is correct |
54 |
Correct |
709 ms |
1004 KB |
Output is correct |
55 |
Correct |
970 ms |
18844 KB |
Output is correct |
56 |
Correct |
1088 ms |
18992 KB |
Output is correct |
57 |
Correct |
1065 ms |
18988 KB |
Output is correct |
58 |
Correct |
704 ms |
18980 KB |
Output is correct |
59 |
Correct |
872 ms |
25252 KB |
Output is correct |
60 |
Correct |
911 ms |
25244 KB |
Output is correct |
61 |
Correct |
617 ms |
856 KB |
Output is correct |
62 |
Correct |
917 ms |
920 KB |
Output is correct |
63 |
Correct |
817 ms |
884 KB |
Output is correct |
64 |
Correct |
926 ms |
1320 KB |
Output is correct |
65 |
Correct |
797 ms |
1328 KB |
Output is correct |
66 |
Correct |
846 ms |
1312 KB |
Output is correct |
67 |
Correct |
862 ms |
1316 KB |
Output is correct |
68 |
Correct |
906 ms |
1308 KB |
Output is correct |
69 |
Correct |
1036 ms |
980 KB |
Output is correct |
70 |
Correct |
864 ms |
996 KB |
Output is correct |
71 |
Correct |
842 ms |
936 KB |
Output is correct |
72 |
Correct |
1028 ms |
1316 KB |
Output is correct |
73 |
Correct |
948 ms |
1132 KB |
Output is correct |
74 |
Correct |
834 ms |
1096 KB |
Output is correct |
75 |
Correct |
687 ms |
944 KB |
Output is correct |
76 |
Correct |
748 ms |
1620 KB |
Output is correct |
77 |
Correct |
975 ms |
1668 KB |
Output is correct |
78 |
Correct |
1081 ms |
1664 KB |
Output is correct |
79 |
Correct |
990 ms |
976 KB |
Output is correct |
80 |
Correct |
749 ms |
832 KB |
Output is correct |
81 |
Correct |
875 ms |
720 KB |
Output is correct |
82 |
Correct |
856 ms |
976 KB |
Output is correct |
83 |
Correct |
498 ms |
640 KB |
Output is correct |
84 |
Correct |
714 ms |
1008 KB |
Output is correct |
85 |
Correct |
927 ms |
1000 KB |
Output is correct |
86 |
Correct |
841 ms |
1020 KB |
Output is correct |
87 |
Correct |
0 ms |
208 KB |
Output is correct |
88 |
Correct |
641 ms |
17620 KB |
Output is correct |
89 |
Correct |
707 ms |
11676 KB |
Output is correct |
90 |
Correct |
947 ms |
11408 KB |
Output is correct |
91 |
Correct |
1074 ms |
19100 KB |
Output is correct |
92 |
Correct |
942 ms |
19096 KB |
Output is correct |
93 |
Correct |
689 ms |
19104 KB |
Output is correct |
94 |
Correct |
949 ms |
19180 KB |
Output is correct |
95 |
Correct |
875 ms |
19104 KB |
Output is correct |
96 |
Execution timed out |
3016 ms |
6208 KB |
Time limit exceeded |
97 |
Halted |
0 ms |
0 KB |
- |