#include "bits/stdc++.h"
#include "circuit.h"
//#define int long long
#define all(v) v.begin() , v.end()
#define sz(a) (int64_t) a.size()
using namespace std;
const int64_t MOD = 1000002022;
int64_t add(int64_t a,int64_t b){
if(a+b>=MOD) return a+b-MOD;
return a+b;
}
int64_t mult(int64_t a,int64_t b){
if(a*b>=MOD) return a*b%MOD;
return a*b;
}
const int N = 1e5 + 5;
vector<int> v[N];
int64_t sub[N],n,m;
vector<int64_t> ans,col;
struct SegT{
vector<array<int64_t,2>> v;
vector<int> lazy;
void init(int n){
lazy.resize(4*n+5,0);
v.resize(4*n+5);
}
array<int64_t,2> merge(array<int64_t,2> a,array<int64_t,2> b){
array<int64_t,2> res;
res[0]=add(a[0],b[0]);
res[1]=add(a[1],b[1]);
return res;
}
void build(int rt,int l,int r){
if(l==r){
v[rt][0]=mult(col[l],ans[l]);
v[rt][1]=mult(1-col[l],ans[l]);
//cout << n+l << ' ' << col[l] << ' ' << v[rt][0] << ' ' << v[rt][1] << '\n';
return;
}
int m=(l+r)/2;
build(rt*2,l,m),build(rt*2+1,m+1,r);
v[rt]=merge(v[rt*2],v[rt*2+1]);
}
void push(int rt,int l,int r){
if(!lazy[rt]) return;
swap(v[rt][0],v[rt][1]);
lazy[rt]=0;
if(l==r) return;
lazy[rt*2]^=1;
lazy[rt*2+1]^=1;
}
void upd(int rt,int l,int r,int gl,int gr){
push(rt,l,r);
if(r<gl || l>gr) return;
if(l>=gl && r<=gr){
lazy[rt]^=1;
push(rt,l,r);
return;
}
int m=(l+r)/2;
upd(rt*2,l,m,gl,gr),upd(rt*2+1,m+1,r,gl,gr);
v[rt]=merge(v[rt*2],v[rt*2+1]);
}
};
SegT seg;
void dfs(int c){
int64_t res=1;
for(int x:v[c]){
dfs(x);
res=mult(res,sub[x]);
}
if(sz(v[c])>0) res=mult(res,sz(v[c]));
sub[c]=res;
}
void dfs2(int c,int64_t val){
if(sz(v[c])==0){
ans[c-n]=val;
return;
}
vector<int64_t> pre(sz(v[c])),suf(sz(v[c]));
int64_t cur=1;
for(int i=0;i<sz(v[c]);i++){
cur=mult(cur,sub[v[c][i]]);
pre[i]=cur;
}
cur=1;
for(int i=sz(v[c])-1;i>=0;i--){
cur=mult(cur,sub[v[c][i]]);
suf[i]=cur;
}
for(int i=0;i<sz(v[c]);i++)
dfs2(v[c][i],mult((i+1<sz(v[c])?suf[i+1]:1),mult(val,(i>0 ? pre[i-1] : 1))));
}
void init(int N, int M, vector<int> P, vector<int> A){
n=N,m=M;
ans.resize(m),col.resize(m);
for(int i=1;i<n+m;i++) v[P[i]].push_back(i);
for(int i=0;i<m;i++) col[i]=A[i];
dfs(0),dfs2(0,1);
seg.init(m);
seg.build(1,0,m-1);
}
int count_ways(int L, int R){
L-=n,R-=n;
seg.upd(1,0,m-1,L,R);
return (int32_t)seg.v[1][0];
}
/*void _(){
cin >> n >> m;
ans.resize(m),col.resize(m);
for(int i=0;i<n+m;i++){
int a;cin >> a;
if(a>=0) v[a].push_back(i);
}
for(int i=0;i<m;i++) cin >> col[i];
dfs(0),dfs2(0,1);
SegT seg(m);
seg.build(1,0,m-1);
int q;cin >> q;
while(q--){
int l,r;
cin >> l >> r;
l-=n;r-=n;
seg.upd(1,0,m-1,l,r);
cout << seg.v[1][0] << '\n';
}
}
int32_t main(){
cin.tie(0); ios::sync_with_stdio(0);
int tc=1;//cin >> tc;
while(tc--) _();
return 0;
}*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
3160 KB |
Output is correct |
2 |
Correct |
1 ms |
3160 KB |
Output is correct |
3 |
Correct |
1 ms |
3416 KB |
Output is correct |
4 |
Correct |
1 ms |
3416 KB |
Output is correct |
5 |
Correct |
1 ms |
3416 KB |
Output is correct |
6 |
Correct |
1 ms |
3416 KB |
Output is correct |
7 |
Correct |
1 ms |
3416 KB |
Output is correct |
8 |
Correct |
1 ms |
3416 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
3160 KB |
Output is correct |
2 |
Correct |
1 ms |
3416 KB |
Output is correct |
3 |
Correct |
1 ms |
3416 KB |
Output is correct |
4 |
Correct |
1 ms |
3416 KB |
Output is correct |
5 |
Correct |
2 ms |
3356 KB |
Output is correct |
6 |
Correct |
1 ms |
3416 KB |
Output is correct |
7 |
Correct |
2 ms |
3416 KB |
Output is correct |
8 |
Correct |
1 ms |
3416 KB |
Output is correct |
9 |
Correct |
2 ms |
3416 KB |
Output is correct |
10 |
Correct |
2 ms |
3672 KB |
Output is correct |
11 |
Correct |
1 ms |
3672 KB |
Output is correct |
12 |
Correct |
1 ms |
3416 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
3160 KB |
Output is correct |
2 |
Correct |
1 ms |
3160 KB |
Output is correct |
3 |
Correct |
1 ms |
3416 KB |
Output is correct |
4 |
Correct |
1 ms |
3416 KB |
Output is correct |
5 |
Correct |
1 ms |
3416 KB |
Output is correct |
6 |
Correct |
1 ms |
3416 KB |
Output is correct |
7 |
Correct |
1 ms |
3416 KB |
Output is correct |
8 |
Correct |
1 ms |
3416 KB |
Output is correct |
9 |
Correct |
1 ms |
3160 KB |
Output is correct |
10 |
Correct |
1 ms |
3416 KB |
Output is correct |
11 |
Correct |
1 ms |
3416 KB |
Output is correct |
12 |
Correct |
1 ms |
3416 KB |
Output is correct |
13 |
Correct |
2 ms |
3356 KB |
Output is correct |
14 |
Correct |
1 ms |
3416 KB |
Output is correct |
15 |
Correct |
2 ms |
3416 KB |
Output is correct |
16 |
Correct |
1 ms |
3416 KB |
Output is correct |
17 |
Correct |
2 ms |
3416 KB |
Output is correct |
18 |
Correct |
2 ms |
3672 KB |
Output is correct |
19 |
Correct |
1 ms |
3672 KB |
Output is correct |
20 |
Correct |
1 ms |
3416 KB |
Output is correct |
21 |
Correct |
1 ms |
3416 KB |
Output is correct |
22 |
Correct |
1 ms |
3416 KB |
Output is correct |
23 |
Correct |
1 ms |
3416 KB |
Output is correct |
24 |
Correct |
2 ms |
3416 KB |
Output is correct |
25 |
Correct |
1 ms |
3416 KB |
Output is correct |
26 |
Correct |
1 ms |
3416 KB |
Output is correct |
27 |
Correct |
1 ms |
3416 KB |
Output is correct |
28 |
Correct |
2 ms |
3416 KB |
Output is correct |
29 |
Correct |
2 ms |
3672 KB |
Output is correct |
30 |
Correct |
2 ms |
3416 KB |
Output is correct |
31 |
Correct |
1 ms |
3416 KB |
Output is correct |
32 |
Correct |
1 ms |
3416 KB |
Output is correct |
33 |
Correct |
1 ms |
3412 KB |
Output is correct |
34 |
Correct |
1 ms |
3416 KB |
Output is correct |
35 |
Correct |
2 ms |
3416 KB |
Output is correct |
36 |
Correct |
1 ms |
3672 KB |
Output is correct |
37 |
Correct |
1 ms |
3672 KB |
Output is correct |
38 |
Correct |
1 ms |
3672 KB |
Output is correct |
39 |
Correct |
1 ms |
3416 KB |
Output is correct |
40 |
Correct |
1 ms |
3416 KB |
Output is correct |
41 |
Correct |
1 ms |
3416 KB |
Output is correct |
42 |
Correct |
1 ms |
3416 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
439 ms |
8280 KB |
Output is correct |
2 |
Runtime error |
27 ms |
16216 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
439 ms |
8280 KB |
Output is correct |
2 |
Runtime error |
27 ms |
16216 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
3160 KB |
Output is correct |
2 |
Correct |
1 ms |
3416 KB |
Output is correct |
3 |
Correct |
1 ms |
3416 KB |
Output is correct |
4 |
Correct |
1 ms |
3416 KB |
Output is correct |
5 |
Correct |
2 ms |
3356 KB |
Output is correct |
6 |
Correct |
1 ms |
3416 KB |
Output is correct |
7 |
Correct |
2 ms |
3416 KB |
Output is correct |
8 |
Correct |
1 ms |
3416 KB |
Output is correct |
9 |
Correct |
2 ms |
3416 KB |
Output is correct |
10 |
Correct |
2 ms |
3672 KB |
Output is correct |
11 |
Correct |
1 ms |
3672 KB |
Output is correct |
12 |
Correct |
1 ms |
3416 KB |
Output is correct |
13 |
Correct |
439 ms |
8280 KB |
Output is correct |
14 |
Runtime error |
27 ms |
16216 KB |
Execution killed with signal 11 |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
3160 KB |
Output is correct |
2 |
Correct |
1 ms |
3160 KB |
Output is correct |
3 |
Correct |
1 ms |
3416 KB |
Output is correct |
4 |
Correct |
1 ms |
3416 KB |
Output is correct |
5 |
Correct |
1 ms |
3416 KB |
Output is correct |
6 |
Correct |
1 ms |
3416 KB |
Output is correct |
7 |
Correct |
1 ms |
3416 KB |
Output is correct |
8 |
Correct |
1 ms |
3416 KB |
Output is correct |
9 |
Correct |
1 ms |
3160 KB |
Output is correct |
10 |
Correct |
1 ms |
3416 KB |
Output is correct |
11 |
Correct |
1 ms |
3416 KB |
Output is correct |
12 |
Correct |
1 ms |
3416 KB |
Output is correct |
13 |
Correct |
2 ms |
3356 KB |
Output is correct |
14 |
Correct |
1 ms |
3416 KB |
Output is correct |
15 |
Correct |
2 ms |
3416 KB |
Output is correct |
16 |
Correct |
1 ms |
3416 KB |
Output is correct |
17 |
Correct |
2 ms |
3416 KB |
Output is correct |
18 |
Correct |
2 ms |
3672 KB |
Output is correct |
19 |
Correct |
1 ms |
3672 KB |
Output is correct |
20 |
Correct |
1 ms |
3416 KB |
Output is correct |
21 |
Correct |
1 ms |
3416 KB |
Output is correct |
22 |
Correct |
1 ms |
3416 KB |
Output is correct |
23 |
Correct |
1 ms |
3416 KB |
Output is correct |
24 |
Correct |
2 ms |
3416 KB |
Output is correct |
25 |
Correct |
1 ms |
3416 KB |
Output is correct |
26 |
Correct |
1 ms |
3416 KB |
Output is correct |
27 |
Correct |
1 ms |
3416 KB |
Output is correct |
28 |
Correct |
2 ms |
3416 KB |
Output is correct |
29 |
Correct |
2 ms |
3672 KB |
Output is correct |
30 |
Correct |
2 ms |
3416 KB |
Output is correct |
31 |
Correct |
1 ms |
3416 KB |
Output is correct |
32 |
Correct |
1 ms |
3416 KB |
Output is correct |
33 |
Correct |
1 ms |
3412 KB |
Output is correct |
34 |
Correct |
1 ms |
3416 KB |
Output is correct |
35 |
Correct |
2 ms |
3416 KB |
Output is correct |
36 |
Correct |
1 ms |
3672 KB |
Output is correct |
37 |
Correct |
1 ms |
3672 KB |
Output is correct |
38 |
Correct |
1 ms |
3672 KB |
Output is correct |
39 |
Correct |
1 ms |
3416 KB |
Output is correct |
40 |
Correct |
1 ms |
3416 KB |
Output is correct |
41 |
Correct |
1 ms |
3416 KB |
Output is correct |
42 |
Correct |
1 ms |
3416 KB |
Output is correct |
43 |
Correct |
438 ms |
3672 KB |
Output is correct |
44 |
Correct |
633 ms |
3672 KB |
Output is correct |
45 |
Correct |
629 ms |
3672 KB |
Output is correct |
46 |
Correct |
619 ms |
4184 KB |
Output is correct |
47 |
Correct |
664 ms |
4184 KB |
Output is correct |
48 |
Correct |
642 ms |
4184 KB |
Output is correct |
49 |
Correct |
641 ms |
4184 KB |
Output is correct |
50 |
Correct |
655 ms |
4180 KB |
Output is correct |
51 |
Correct |
630 ms |
3928 KB |
Output is correct |
52 |
Correct |
650 ms |
3928 KB |
Output is correct |
53 |
Correct |
578 ms |
4696 KB |
Output is correct |
54 |
Correct |
649 ms |
4184 KB |
Output is correct |
55 |
Correct |
640 ms |
4104 KB |
Output is correct |
56 |
Correct |
620 ms |
3928 KB |
Output is correct |
57 |
Correct |
665 ms |
3996 KB |
Output is correct |
58 |
Correct |
640 ms |
5208 KB |
Output is correct |
59 |
Correct |
629 ms |
5208 KB |
Output is correct |
60 |
Correct |
573 ms |
5208 KB |
Output is correct |
61 |
Correct |
652 ms |
3928 KB |
Output is correct |
62 |
Correct |
610 ms |
3928 KB |
Output is correct |
63 |
Correct |
592 ms |
3908 KB |
Output is correct |
64 |
Correct |
671 ms |
3928 KB |
Output is correct |
65 |
Correct |
308 ms |
3672 KB |
Output is correct |
66 |
Correct |
636 ms |
4076 KB |
Output is correct |
67 |
Correct |
642 ms |
4064 KB |
Output is correct |
68 |
Correct |
623 ms |
4076 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
3160 KB |
Output is correct |
2 |
Correct |
1 ms |
3160 KB |
Output is correct |
3 |
Correct |
1 ms |
3416 KB |
Output is correct |
4 |
Correct |
1 ms |
3416 KB |
Output is correct |
5 |
Correct |
1 ms |
3416 KB |
Output is correct |
6 |
Correct |
1 ms |
3416 KB |
Output is correct |
7 |
Correct |
1 ms |
3416 KB |
Output is correct |
8 |
Correct |
1 ms |
3416 KB |
Output is correct |
9 |
Correct |
1 ms |
3160 KB |
Output is correct |
10 |
Correct |
1 ms |
3416 KB |
Output is correct |
11 |
Correct |
1 ms |
3416 KB |
Output is correct |
12 |
Correct |
1 ms |
3416 KB |
Output is correct |
13 |
Correct |
2 ms |
3356 KB |
Output is correct |
14 |
Correct |
1 ms |
3416 KB |
Output is correct |
15 |
Correct |
2 ms |
3416 KB |
Output is correct |
16 |
Correct |
1 ms |
3416 KB |
Output is correct |
17 |
Correct |
2 ms |
3416 KB |
Output is correct |
18 |
Correct |
2 ms |
3672 KB |
Output is correct |
19 |
Correct |
1 ms |
3672 KB |
Output is correct |
20 |
Correct |
1 ms |
3416 KB |
Output is correct |
21 |
Correct |
1 ms |
3416 KB |
Output is correct |
22 |
Correct |
1 ms |
3416 KB |
Output is correct |
23 |
Correct |
1 ms |
3416 KB |
Output is correct |
24 |
Correct |
2 ms |
3416 KB |
Output is correct |
25 |
Correct |
1 ms |
3416 KB |
Output is correct |
26 |
Correct |
1 ms |
3416 KB |
Output is correct |
27 |
Correct |
1 ms |
3416 KB |
Output is correct |
28 |
Correct |
2 ms |
3416 KB |
Output is correct |
29 |
Correct |
2 ms |
3672 KB |
Output is correct |
30 |
Correct |
2 ms |
3416 KB |
Output is correct |
31 |
Correct |
1 ms |
3416 KB |
Output is correct |
32 |
Correct |
1 ms |
3416 KB |
Output is correct |
33 |
Correct |
1 ms |
3412 KB |
Output is correct |
34 |
Correct |
1 ms |
3416 KB |
Output is correct |
35 |
Correct |
2 ms |
3416 KB |
Output is correct |
36 |
Correct |
1 ms |
3672 KB |
Output is correct |
37 |
Correct |
1 ms |
3672 KB |
Output is correct |
38 |
Correct |
1 ms |
3672 KB |
Output is correct |
39 |
Correct |
1 ms |
3416 KB |
Output is correct |
40 |
Correct |
1 ms |
3416 KB |
Output is correct |
41 |
Correct |
1 ms |
3416 KB |
Output is correct |
42 |
Correct |
1 ms |
3416 KB |
Output is correct |
43 |
Correct |
439 ms |
8280 KB |
Output is correct |
44 |
Runtime error |
27 ms |
16216 KB |
Execution killed with signal 11 |
45 |
Halted |
0 ms |
0 KB |
- |