#include<bits/stdc++.h>
#define MAXN 800007
using namespace std;
const long long mod=1000002022;
int n,m,maxdep,pw;
long long st[MAXN],total,diff,zeros,ans,a[MAXN];
vector<int> v[MAXN];
long long power(long long x,int y){
if(y==0)return 1;
if(y==1)return x;
if(y==2)return (x*x)%mod;
if(y%2==0)return power(power(x,y/2),2);
return (power(power(x,y/2),2)*x)%mod;
}
void dfs2(int x,int dep){
if(v[x].empty()){
st[x]=power(2,n-dep);
return;
}
for(int i=0;i<v[x].size();i++){
dfs2(v[x][i],dep+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;
lazy[v]=0;
}
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;
for(int i=1;i<N+M;i++){
v[P[i]].push_back(i);
}
dfs2(0,0);
for(int i=0;i<M;i++){
a[i]=A[i];
ans+=a[i]*st[i+N];
ans%=mod;
}
//cout<<ans<<"\n";
}
int count_ways(int L, int R){
L-=n; R-=n;
for(int i=L;i<=R;i++){
ans-=a[i]*st[i+n]; a[i]^=1;
ans+=a[i]*st[i+n]+mod;
ans%=mod;
}
return ans;
}
/*
int main(){
init(7, 8, {-1, 0, 0,1,1,2,2,3,3,4,4,5,5,6,6}, {0,0,0,0,0,0,0,0});
cout<<count_ways(7,14)<<"\n";
}
*/
Compilation message
circuit.cpp: In function 'void dfs2(int, int)':
circuit.cpp:25:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
25 | 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 |
Correct |
9 ms |
19024 KB |
Output is correct |
3 |
Correct |
10 ms |
19100 KB |
Output is correct |
4 |
Correct |
10 ms |
19092 KB |
Output is correct |
5 |
Correct |
9 ms |
19152 KB |
Output is correct |
6 |
Correct |
10 ms |
19060 KB |
Output is correct |
7 |
Correct |
10 ms |
19092 KB |
Output is correct |
8 |
Correct |
10 ms |
19024 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
19024 KB |
Output is correct |
2 |
Correct |
10 ms |
19024 KB |
Output is correct |
3 |
Correct |
10 ms |
19024 KB |
Output is correct |
4 |
Correct |
9 ms |
19024 KB |
Output is correct |
5 |
Correct |
10 ms |
19024 KB |
Output is correct |
6 |
Correct |
10 ms |
19152 KB |
Output is correct |
7 |
Correct |
12 ms |
19152 KB |
Output is correct |
8 |
Correct |
10 ms |
19088 KB |
Output is correct |
9 |
Correct |
10 ms |
19152 KB |
Output is correct |
10 |
Correct |
12 ms |
19152 KB |
Output is correct |
11 |
Correct |
10 ms |
19152 KB |
Output is correct |
12 |
Correct |
10 ms |
19152 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
19024 KB |
Output is correct |
2 |
Correct |
9 ms |
19024 KB |
Output is correct |
3 |
Correct |
10 ms |
19100 KB |
Output is correct |
4 |
Correct |
10 ms |
19092 KB |
Output is correct |
5 |
Correct |
9 ms |
19152 KB |
Output is correct |
6 |
Correct |
10 ms |
19060 KB |
Output is correct |
7 |
Correct |
10 ms |
19092 KB |
Output is correct |
8 |
Correct |
10 ms |
19024 KB |
Output is correct |
9 |
Correct |
9 ms |
19024 KB |
Output is correct |
10 |
Correct |
10 ms |
19024 KB |
Output is correct |
11 |
Correct |
10 ms |
19024 KB |
Output is correct |
12 |
Correct |
9 ms |
19024 KB |
Output is correct |
13 |
Correct |
10 ms |
19024 KB |
Output is correct |
14 |
Correct |
10 ms |
19152 KB |
Output is correct |
15 |
Correct |
12 ms |
19152 KB |
Output is correct |
16 |
Correct |
10 ms |
19088 KB |
Output is correct |
17 |
Correct |
10 ms |
19152 KB |
Output is correct |
18 |
Correct |
12 ms |
19152 KB |
Output is correct |
19 |
Correct |
10 ms |
19152 KB |
Output is correct |
20 |
Correct |
10 ms |
19152 KB |
Output is correct |
21 |
Incorrect |
9 ms |
19152 KB |
1st lines differ - on the 1st token, expected: '759476520', found: '833967706' |
22 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
527 ms |
21428 KB |
Output is correct |
2 |
Correct |
670 ms |
23628 KB |
Output is correct |
3 |
Correct |
727 ms |
23700 KB |
Output is correct |
4 |
Correct |
751 ms |
23700 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
527 ms |
21428 KB |
Output is correct |
2 |
Correct |
670 ms |
23628 KB |
Output is correct |
3 |
Correct |
727 ms |
23700 KB |
Output is correct |
4 |
Correct |
751 ms |
23700 KB |
Output is correct |
5 |
Execution timed out |
3024 ms |
21328 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
19024 KB |
Output is correct |
2 |
Correct |
10 ms |
19024 KB |
Output is correct |
3 |
Correct |
10 ms |
19024 KB |
Output is correct |
4 |
Correct |
9 ms |
19024 KB |
Output is correct |
5 |
Correct |
10 ms |
19024 KB |
Output is correct |
6 |
Correct |
10 ms |
19152 KB |
Output is correct |
7 |
Correct |
12 ms |
19152 KB |
Output is correct |
8 |
Correct |
10 ms |
19088 KB |
Output is correct |
9 |
Correct |
10 ms |
19152 KB |
Output is correct |
10 |
Correct |
12 ms |
19152 KB |
Output is correct |
11 |
Correct |
10 ms |
19152 KB |
Output is correct |
12 |
Correct |
10 ms |
19152 KB |
Output is correct |
13 |
Correct |
527 ms |
21428 KB |
Output is correct |
14 |
Correct |
670 ms |
23628 KB |
Output is correct |
15 |
Correct |
727 ms |
23700 KB |
Output is correct |
16 |
Correct |
751 ms |
23700 KB |
Output is correct |
17 |
Execution timed out |
3024 ms |
21328 KB |
Time limit exceeded |
18 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
19024 KB |
Output is correct |
2 |
Correct |
9 ms |
19024 KB |
Output is correct |
3 |
Correct |
10 ms |
19100 KB |
Output is correct |
4 |
Correct |
10 ms |
19092 KB |
Output is correct |
5 |
Correct |
9 ms |
19152 KB |
Output is correct |
6 |
Correct |
10 ms |
19060 KB |
Output is correct |
7 |
Correct |
10 ms |
19092 KB |
Output is correct |
8 |
Correct |
10 ms |
19024 KB |
Output is correct |
9 |
Correct |
9 ms |
19024 KB |
Output is correct |
10 |
Correct |
10 ms |
19024 KB |
Output is correct |
11 |
Correct |
10 ms |
19024 KB |
Output is correct |
12 |
Correct |
9 ms |
19024 KB |
Output is correct |
13 |
Correct |
10 ms |
19024 KB |
Output is correct |
14 |
Correct |
10 ms |
19152 KB |
Output is correct |
15 |
Correct |
12 ms |
19152 KB |
Output is correct |
16 |
Correct |
10 ms |
19088 KB |
Output is correct |
17 |
Correct |
10 ms |
19152 KB |
Output is correct |
18 |
Correct |
12 ms |
19152 KB |
Output is correct |
19 |
Correct |
10 ms |
19152 KB |
Output is correct |
20 |
Correct |
10 ms |
19152 KB |
Output is correct |
21 |
Incorrect |
9 ms |
19152 KB |
1st lines differ - on the 1st token, expected: '759476520', found: '833967706' |
22 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
19024 KB |
Output is correct |
2 |
Correct |
9 ms |
19024 KB |
Output is correct |
3 |
Correct |
10 ms |
19100 KB |
Output is correct |
4 |
Correct |
10 ms |
19092 KB |
Output is correct |
5 |
Correct |
9 ms |
19152 KB |
Output is correct |
6 |
Correct |
10 ms |
19060 KB |
Output is correct |
7 |
Correct |
10 ms |
19092 KB |
Output is correct |
8 |
Correct |
10 ms |
19024 KB |
Output is correct |
9 |
Correct |
9 ms |
19024 KB |
Output is correct |
10 |
Correct |
10 ms |
19024 KB |
Output is correct |
11 |
Correct |
10 ms |
19024 KB |
Output is correct |
12 |
Correct |
9 ms |
19024 KB |
Output is correct |
13 |
Correct |
10 ms |
19024 KB |
Output is correct |
14 |
Correct |
10 ms |
19152 KB |
Output is correct |
15 |
Correct |
12 ms |
19152 KB |
Output is correct |
16 |
Correct |
10 ms |
19088 KB |
Output is correct |
17 |
Correct |
10 ms |
19152 KB |
Output is correct |
18 |
Correct |
12 ms |
19152 KB |
Output is correct |
19 |
Correct |
10 ms |
19152 KB |
Output is correct |
20 |
Correct |
10 ms |
19152 KB |
Output is correct |
21 |
Incorrect |
9 ms |
19152 KB |
1st lines differ - on the 1st token, expected: '759476520', found: '833967706' |
22 |
Halted |
0 ms |
0 KB |
- |