#include "circuit.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll MOD = 1000002022;
const int MAXN = 1e5+5;
vector<int>adj[MAXN];
ll c[MAXN],sub[MAXN];
int n,m;
void dfs(int v){
if(adj[v].empty())sub[v] = 1;
else sub[v] = adj[v].size();
for(int x:adj[v]){
dfs(x);
sub[v] = sub[v]*sub[x]%MOD;
}
}
void dfs(int v,ll cur){
if(adj[v].empty()){
c[v-n] = cur;
return;
}
int s = adj[v].size();
vector<ll>pref(s,1),suff(s,1);
for(int i=0;i<s;i++){
pref[i] = sub[adj[v][i]];
suff[i] = sub[adj[v][i]];
if(i)pref[i] = pref[i]*pref[i-1]%MOD;
}
for(int i=s-2;i>=0;i--)suff[i] = suff[i]*suff[i+1]%MOD;
for(int i=0;i<s;i++){
ll k = 1;
if(i)k = pref[i-1]*k%MOD;
if(i!=s-1)k = suff[i+1]*k%MOD;
dfs(adj[v][i],(cur*k)%MOD);
}
}
ll ans = 0;
vector<int>a;
ll t[4*MAXN],sum[4*MAXN];
bool lazy[4*MAXN];
void pushdown(int v){
if(lazy[v]){
t[2*v] = sum[2*v] - t[2*v] + MOD;
t[2*v+1] = sum[2*v+1] - t[2*v+1] + MOD;
if(t[2*v]>=MOD)t[2*v]-=MOD;
if(t[2*v+1]>=MOD)t[2*v+1]-=MOD;
lazy[2*v]^=1;
lazy[2*v+1]^=1;
lazy[v] = 0;
}
}
void upd(int v,int l,int r,int tl,int tr){
if(l>r)return;
if(l==tl && r==tr){
lazy[v]^=1;
t[v] = sum[v]-t[v]+MOD;
if(t[v]>=MOD)t[v]-=MOD;
return;
}
int tm = (tl+tr)/2;
pushdown(v);
upd(2*v,l,min(r,tm),tl,tm);
upd(2*v+1,max(tm+1,l),r,tm+1,tr);
t[v] = t[2*v] + t[2*v+1];
}
void build(int v,int l,int r){
if(l==r){
sum[v] = c[l];
if(a[l])t[v] = c[l];
return;
}
int tm = (l+r)/2;
build(2*v,l,tm);
build(2*v+1,tm+1,r);
t[v] = t[2*v]+t[2*v+1];
sum[v] = sum[2*v]+sum[2*v+1];
}
void init(int N, int M, vector<int> p, vector<int> A) {
n = N;
m = M;
a = A;
for(int i=1;i<n+m;i++)adj[p[i]].push_back(i);
dfs(0);
dfs(0,1);
build(1,0,m-1);
}
int count_ways(int L, int R) {
L-=n;
R-=n;
upd(1,L,R,0,m-1);
return t[1];
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2640 KB |
Output is correct |
2 |
Correct |
2 ms |
2640 KB |
Output is correct |
3 |
Correct |
2 ms |
2640 KB |
Output is correct |
4 |
Correct |
2 ms |
2768 KB |
Output is correct |
5 |
Correct |
2 ms |
2768 KB |
Output is correct |
6 |
Correct |
3 ms |
2768 KB |
Output is correct |
7 |
Correct |
2 ms |
2768 KB |
Output is correct |
8 |
Correct |
2 ms |
2640 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2640 KB |
Output is correct |
2 |
Incorrect |
2 ms |
2640 KB |
1st lines differ - on the 1st token, expected: '52130940', found: '-1782334720' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2640 KB |
Output is correct |
2 |
Correct |
2 ms |
2640 KB |
Output is correct |
3 |
Correct |
2 ms |
2640 KB |
Output is correct |
4 |
Correct |
2 ms |
2768 KB |
Output is correct |
5 |
Correct |
2 ms |
2768 KB |
Output is correct |
6 |
Correct |
3 ms |
2768 KB |
Output is correct |
7 |
Correct |
2 ms |
2768 KB |
Output is correct |
8 |
Correct |
2 ms |
2640 KB |
Output is correct |
9 |
Correct |
2 ms |
2640 KB |
Output is correct |
10 |
Incorrect |
2 ms |
2640 KB |
1st lines differ - on the 1st token, expected: '52130940', found: '-1782334720' |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
674 ms |
6340 KB |
1st lines differ - on the 1st token, expected: '431985922', found: '-747097920' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
674 ms |
6340 KB |
1st lines differ - on the 1st token, expected: '431985922', found: '-747097920' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2640 KB |
Output is correct |
2 |
Incorrect |
2 ms |
2640 KB |
1st lines differ - on the 1st token, expected: '52130940', found: '-1782334720' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2640 KB |
Output is correct |
2 |
Correct |
2 ms |
2640 KB |
Output is correct |
3 |
Correct |
2 ms |
2640 KB |
Output is correct |
4 |
Correct |
2 ms |
2768 KB |
Output is correct |
5 |
Correct |
2 ms |
2768 KB |
Output is correct |
6 |
Correct |
3 ms |
2768 KB |
Output is correct |
7 |
Correct |
2 ms |
2768 KB |
Output is correct |
8 |
Correct |
2 ms |
2640 KB |
Output is correct |
9 |
Correct |
2 ms |
2640 KB |
Output is correct |
10 |
Incorrect |
2 ms |
2640 KB |
1st lines differ - on the 1st token, expected: '52130940', found: '-1782334720' |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2640 KB |
Output is correct |
2 |
Correct |
2 ms |
2640 KB |
Output is correct |
3 |
Correct |
2 ms |
2640 KB |
Output is correct |
4 |
Correct |
2 ms |
2768 KB |
Output is correct |
5 |
Correct |
2 ms |
2768 KB |
Output is correct |
6 |
Correct |
3 ms |
2768 KB |
Output is correct |
7 |
Correct |
2 ms |
2768 KB |
Output is correct |
8 |
Correct |
2 ms |
2640 KB |
Output is correct |
9 |
Correct |
2 ms |
2640 KB |
Output is correct |
10 |
Incorrect |
2 ms |
2640 KB |
1st lines differ - on the 1st token, expected: '52130940', found: '-1782334720' |
11 |
Halted |
0 ms |
0 KB |
- |