//by szh
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pii pair<int,int>
#define pll pair<long long,long long>
#define pb push_back
#define debug(x) cerr<<#x<<"="<<x<<endl
#define pq priority_queue
#define inf 0x3f
#define rep(i,a,b) for (int i=a;i<(b);i++)
#define MP make_pair
#define SZ(x) (int(x.size()))
#define ll long long
#define mod 1000002022
#define ALL(x) x.begin(),x.end()
void inc(int &a,int b) {a=(a+b)%mod;}
void dec(int &a,int b) {a=(a-b+mod)%mod;}
int lowbit(int x) {return x&(-x);}
ll p0w(ll base,ll p) {ll ret=1;while(p>0){if (p%2ll==1ll) ret=ret*base%mod;base=base*base%mod;p/=2ll;}return ret;}
#include "circuit.h"
const int maxn = 200010;
int a[maxn];
vector <int> edge[maxn];
int NN,MM;
pii tree[maxn*4];
int add[maxn*4];
int sum[maxn];
void initt(int c,int cl,int cr) {
if (cl==cr) {
tree[c] = {a[cl],a[cl]^1};
sum[c]=1;
return;
}
int mid=cl+cr>>1;
initt(c<<1,cl,mid);
initt(c<<1|1,mid+1,cr);
sum[c] = 2ll*sum[c<<1]*sum[c<<1|1]%mod;
tree[c].fi = (1ll*tree[c<<1].fi*sum[c<<1|1]%mod + 1ll*tree[c<<1|1].fi*sum[c<<1]%mod)%mod;
tree[c].se = (1ll*tree[c<<1].se*sum[c<<1|1]%mod + 1ll*tree[c<<1|1].se*sum[c<<1]%mod)%mod;
// cout<<cl<<" "<<cr<<" "<<tree[c].fi<<" "<<tree[c].se<<endl;
}
void update(int c,int cl,int cr,int l,int r) {
if (l<=cl and cr<=r) {
add[c]^=1;
swap(tree[c].fi,tree[c].se);
return;
}
if (add[c]==1) {
add[c<<1]^=1,add[c<<1|1]^=1;
swap(tree[c<<1].fi,tree[c<<1].se);
swap(tree[c<<1|1].fi,tree[c<<1|1].se);
add[c] = 0;
}
int mid=cl+cr>>1;
if (l<=mid) update(c<<1,cl,mid,l,r);
if (r>mid) update(c<<1|1,mid+1,cr,l,r);
tree[c].fi = (1ll*tree[c<<1].fi*sum[c<<1|1]%mod + 1ll*tree[c<<1|1].fi*sum[c<<1]%mod)%mod;
tree[c].se = (1ll*tree[c<<1].se*sum[c<<1|1]%mod + 1ll*tree[c<<1|1].se*sum[c<<1]%mod)%mod;
return;
}
void init(int N, int M, std::vector<int> P, std::vector<int> A) {
NN=N,MM=M;
rep(i,1,SZ(P)) {
edge[P[i]].pb(i);
}
rep(i,0,SZ(A)) a[i+N]=A[i];
initt(1,N,N+M-1);
}
pii solve(int u) {
if (SZ(edge[u])==0) {
if (a[u]==0) return {0,1};
else return {1,0};
}
vector <pii> ans;
for (int v:edge[u]) {
ans.pb(solve(v));
}
vector <int> f;
f.pb(1);
rep(i,0,SZ(ans)) {
f.pb(1ll*f.back()*ans[i].fi%mod);
for (int j = i;j>=0;j--) {
f[j] = 1ll*f[j]*ans[i].se%mod;
if (j>0) inc(f[j],1ll*f[j-1]*ans[i].fi%mod);
}
}
pii ret = {0,0};
rep(i,0,SZ(f)) {
inc(ret.se,1ll*f[i]*(SZ(f)-1-i)%mod);
inc(ret.fi,1ll*f[i]*i%mod);
}
return ret;
}
int count_ways(int L, int R) {
if (NN<=1) {
rep(i,L,R+1) a[i]^=1;
return solve(0).fi;
}
update(1,NN,NN+MM-1,L,R);
return tree[1].fi;
}
Compilation message
circuit.cpp: In function 'void initt(int, int, int)':
circuit.cpp:40:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
40 | int mid=cl+cr>>1;
| ~~^~~
circuit.cpp: In function 'void update(int, int, int, int, int)':
circuit.cpp:61:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
61 | int mid=cl+cr>>1;
| ~~^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4944 KB |
Output is correct |
2 |
Correct |
3 ms |
4944 KB |
Output is correct |
3 |
Correct |
15 ms |
5072 KB |
Output is correct |
4 |
Correct |
15 ms |
5072 KB |
Output is correct |
5 |
Correct |
16 ms |
5076 KB |
Output is correct |
6 |
Correct |
16 ms |
5080 KB |
Output is correct |
7 |
Correct |
16 ms |
5016 KB |
Output is correct |
8 |
Correct |
15 ms |
5072 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4944 KB |
Output is correct |
2 |
Correct |
3 ms |
4944 KB |
Output is correct |
3 |
Correct |
3 ms |
5072 KB |
Output is correct |
4 |
Correct |
3 ms |
5072 KB |
Output is correct |
5 |
Correct |
3 ms |
4956 KB |
Output is correct |
6 |
Incorrect |
3 ms |
5072 KB |
1st lines differ - on the 1st token, expected: '706880838', found: '518808754' |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4944 KB |
Output is correct |
2 |
Correct |
3 ms |
4944 KB |
Output is correct |
3 |
Correct |
15 ms |
5072 KB |
Output is correct |
4 |
Correct |
15 ms |
5072 KB |
Output is correct |
5 |
Correct |
16 ms |
5076 KB |
Output is correct |
6 |
Correct |
16 ms |
5080 KB |
Output is correct |
7 |
Correct |
16 ms |
5016 KB |
Output is correct |
8 |
Correct |
15 ms |
5072 KB |
Output is correct |
9 |
Correct |
3 ms |
4944 KB |
Output is correct |
10 |
Correct |
3 ms |
4944 KB |
Output is correct |
11 |
Correct |
3 ms |
5072 KB |
Output is correct |
12 |
Correct |
3 ms |
5072 KB |
Output is correct |
13 |
Correct |
3 ms |
4956 KB |
Output is correct |
14 |
Incorrect |
3 ms |
5072 KB |
1st lines differ - on the 1st token, expected: '706880838', found: '518808754' |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
532 ms |
7824 KB |
Output is correct |
2 |
Correct |
924 ms |
10392 KB |
Output is correct |
3 |
Correct |
866 ms |
10388 KB |
Output is correct |
4 |
Correct |
896 ms |
10308 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
532 ms |
7824 KB |
Output is correct |
2 |
Correct |
924 ms |
10392 KB |
Output is correct |
3 |
Correct |
866 ms |
10388 KB |
Output is correct |
4 |
Correct |
896 ms |
10308 KB |
Output is correct |
5 |
Correct |
729 ms |
7708 KB |
Output is correct |
6 |
Correct |
864 ms |
10312 KB |
Output is correct |
7 |
Correct |
903 ms |
10396 KB |
Output is correct |
8 |
Correct |
877 ms |
10372 KB |
Output is correct |
9 |
Correct |
350 ms |
5200 KB |
Output is correct |
10 |
Correct |
686 ms |
5328 KB |
Output is correct |
11 |
Correct |
883 ms |
5332 KB |
Output is correct |
12 |
Correct |
790 ms |
5328 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4944 KB |
Output is correct |
2 |
Correct |
3 ms |
4944 KB |
Output is correct |
3 |
Correct |
3 ms |
5072 KB |
Output is correct |
4 |
Correct |
3 ms |
5072 KB |
Output is correct |
5 |
Correct |
3 ms |
4956 KB |
Output is correct |
6 |
Incorrect |
3 ms |
5072 KB |
1st lines differ - on the 1st token, expected: '706880838', found: '518808754' |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4944 KB |
Output is correct |
2 |
Correct |
3 ms |
4944 KB |
Output is correct |
3 |
Correct |
15 ms |
5072 KB |
Output is correct |
4 |
Correct |
15 ms |
5072 KB |
Output is correct |
5 |
Correct |
16 ms |
5076 KB |
Output is correct |
6 |
Correct |
16 ms |
5080 KB |
Output is correct |
7 |
Correct |
16 ms |
5016 KB |
Output is correct |
8 |
Correct |
15 ms |
5072 KB |
Output is correct |
9 |
Correct |
3 ms |
4944 KB |
Output is correct |
10 |
Correct |
3 ms |
4944 KB |
Output is correct |
11 |
Correct |
3 ms |
5072 KB |
Output is correct |
12 |
Correct |
3 ms |
5072 KB |
Output is correct |
13 |
Correct |
3 ms |
4956 KB |
Output is correct |
14 |
Incorrect |
3 ms |
5072 KB |
1st lines differ - on the 1st token, expected: '706880838', found: '518808754' |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4944 KB |
Output is correct |
2 |
Correct |
3 ms |
4944 KB |
Output is correct |
3 |
Correct |
15 ms |
5072 KB |
Output is correct |
4 |
Correct |
15 ms |
5072 KB |
Output is correct |
5 |
Correct |
16 ms |
5076 KB |
Output is correct |
6 |
Correct |
16 ms |
5080 KB |
Output is correct |
7 |
Correct |
16 ms |
5016 KB |
Output is correct |
8 |
Correct |
15 ms |
5072 KB |
Output is correct |
9 |
Correct |
3 ms |
4944 KB |
Output is correct |
10 |
Correct |
3 ms |
4944 KB |
Output is correct |
11 |
Correct |
3 ms |
5072 KB |
Output is correct |
12 |
Correct |
3 ms |
5072 KB |
Output is correct |
13 |
Correct |
3 ms |
4956 KB |
Output is correct |
14 |
Incorrect |
3 ms |
5072 KB |
1st lines differ - on the 1st token, expected: '706880838', found: '518808754' |
15 |
Halted |
0 ms |
0 KB |
- |