#include<bits/stdc++.h>
#define MAXN 800007
using namespace std;
const long long mod=1000002022;
int n,m;
long long black[MAXN],white[MAXN];
long long prod[MAXN],total,diff,zeros;
vector<int> v[MAXN];
void dfs(int x){
if(v[x].size()==0){
prod[x]=1; return;
}
prod[x]=1;
for(int i=0;i<v[x].size();i++){
dfs(v[x][i]);
prod[x]*=prod[v[x][i]];
prod[x]%=mod;
}
prod[x]*=2; prod[x]%=mod;
black[x]=0;
/* c=2 */ black[x]+=black[v[x][0]]*black[v[x][1]];
/* c=1 */ black[x]+=black[v[x][0]]*black[v[x][1]]+black[v[x][0]]*white[v[x][1]]+white[v[x][0]]*black[v[x][1]];
black[x]%=mod;
white[x]=(prod[x]-black[x]+mod)%mod;
}
long long power(long long x,int y){
if(y==0)return 1;
return (power(x,y-1)*x)%mod;
}
int lg(int x){
if(x==1)return 0;
return lg(x/2)+1;
}
int tree[MAXN],lazy[MAXN];
void psh(int v,int l,int r){
if(lazy[v]==0)return;
int tt=(l+r)/2;
tree[2*v]=(tt-l+1)-tree[2*v];
lazy[2*v]^=1;
tree[2*v+1]=(r-(tt+1)+1)-tree[2*v+1];
lazy[2*v+1]^=1;
}
void update(int v,int l,int r,int ll,int rr){
if(ll>rr)return;
if(l==ll and r==rr){
tree[v]=(r-l+1)-tree[v];
lazy[v]^=1;
}else{
int tt=(l+r)/2;
psh(v,l,r);
update(2*v,l,tt,ll,min(tt,rr));
update(2*v+1,tt+1,r,max(tt+1,ll),rr);
tree[v]=tree[2*v]+tree[2*v+1];
}
}
void init(int N, int M,vector<int> P,vector<int> A){
n=N; m=M;
total=power(2,N);
diff=power(2,N-lg(N+1));
for(int i=0;i<M;i++){
if(A[i]==1)update(1,0,M-1,i,i);
}
}
int count_ways(int L, int R){
L-=n; R-=n;
update(1,0,m-1,L,R);
zeros=m-tree[1];
return (total-(diff*zeros)+mod*zeros)%mod;
}
/*
int main(){
init(15, 16, {-1, 0, 0, 1, 1, 2, 2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,14,14,15,15}, {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1});
cout<<count_ways(15,29)<<"\n";
}
*/
Compilation message
circuit.cpp: In function 'void dfs(int)':
circuit.cpp:18:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
18 | for(int i=0;i<v[x].size();i++){
| ~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
19024 KB |
Output is correct |
2 |
Incorrect |
9 ms |
19024 KB |
1st lines differ - on the 1st token, expected: '1', found: '2' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
19024 KB |
Output is correct |
2 |
Correct |
9 ms |
19024 KB |
Output is correct |
3 |
Incorrect |
8 ms |
19024 KB |
5th lines differ - on the 1st token, expected: '70832346', found: '563623630' |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
19024 KB |
Output is correct |
2 |
Incorrect |
9 ms |
19024 KB |
1st lines differ - on the 1st token, expected: '1', found: '2' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
619 ms |
20536 KB |
Output is correct |
2 |
Correct |
784 ms |
21932 KB |
Output is correct |
3 |
Correct |
719 ms |
21908 KB |
Output is correct |
4 |
Correct |
812 ms |
21172 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
619 ms |
20536 KB |
Output is correct |
2 |
Correct |
784 ms |
21932 KB |
Output is correct |
3 |
Correct |
719 ms |
21908 KB |
Output is correct |
4 |
Correct |
812 ms |
21172 KB |
Output is correct |
5 |
Incorrect |
755 ms |
20432 KB |
5th lines differ - on the 1st token, expected: '882566410', found: '40177750' |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
19024 KB |
Output is correct |
2 |
Correct |
9 ms |
19024 KB |
Output is correct |
3 |
Incorrect |
8 ms |
19024 KB |
5th lines differ - on the 1st token, expected: '70832346', found: '563623630' |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
19024 KB |
Output is correct |
2 |
Incorrect |
9 ms |
19024 KB |
1st lines differ - on the 1st token, expected: '1', found: '2' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
19024 KB |
Output is correct |
2 |
Incorrect |
9 ms |
19024 KB |
1st lines differ - on the 1st token, expected: '1', found: '2' |
3 |
Halted |
0 ms |
0 KB |
- |