#include "circuit.h"
#include <vector>
#include <bits/stdc++.h>
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,popcnt,sse4")
using namespace std;
#define ll long long
#define pll pair<ll,ll>
#define fs first
#define sc second
const int mxn = 2e5+10;
const ll mod = 1000002022;
vector<int> tree[mxn];
int par[mxn];
int N,M;
ll dp[mxn];
int sz[mxn];
ll arr[mxn];
ll mad(ll a,ll b){
a += b;
return a>=mod?a-mod:a;
}
ll mub(ll a,ll b){
return mad(a,mod-b);
}
ll pw(ll a,ll b){
ll re = 1;
while(b){
if(b&1)re = re*a%mod;
b>>=1;
a = a*a%mod;
}
return re;
}
void dfs(int now){
dp[now] = sz[now] = 1;
for(auto nxt:tree[now]){
dfs(nxt);
sz[now] = sz[nxt]*sz[now]%mod;
}
if(tree[now].size())sz[now] = sz[now]*tree[now].size()%mod;
return;
}
void dfs1(int now){
ll sum = 0;
for(auto nxt:tree[now])sum = mad(sum,sz[nxt]);
for(auto nxt:tree[now]){
ll ts = mub(sum,sz[nxt]);
dp[nxt] = dp[now]*dp[nxt]*ts%mod;
dfs1(nxt);
}
return;
}
void init(int N1, int M1, std::vector<int> P, std::vector<int> A) {
N = N1,M = M1;
for(int i = 1;i<N+M;i++){
par[i] = P[i];
tree[par[i]].push_back(i);
}
for(int i = 0;i<M;i++){
arr[i+N] = A[i];
}
dfs(0);
dfs1(0);
/*
cerr<<"SZ: ";
for(int i = 0;i<N+M;i++)cerr<<sz[i]<<' ';cerr<<endl;
cerr<<"DP: ";
for(int i = 0;i<N+M;i++)cerr<<dp[i]<<' ';cerr<<endl;
//for(int i = 0;i<N+M;i++)cerr<<dp[i][0]<<','<<dp[i][1]<<' ';cerr<<endl;
*/
}
int count_ways(int L, int R) {
for(int i = L;i<=R;i++){
arr[i] ^= 1;
}
//cerr<<"NOW: ";for(int i = N;i<N+M;i++)cerr<<arr[i]<<' ';cerr<<endl;
ll ans = 0;
for(int i = N;i<N+M;i++)ans = mad(ans,dp[i]*arr[i]%mod);
return ans;
//dfs(0);
//cerr<<"NOW: ";
//for(int i = N;i<N+M;i++)cerr<<(dp[i][0]?0:1);cerr<<endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4952 KB |
Output is correct |
2 |
Incorrect |
4 ms |
4952 KB |
1st lines differ - on the 1st token, expected: '1', found: '0' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4952 KB |
Output is correct |
2 |
Incorrect |
2 ms |
4952 KB |
1st lines differ - on the 1st token, expected: '52130940', found: '218061342' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4952 KB |
Output is correct |
2 |
Incorrect |
4 ms |
4952 KB |
1st lines differ - on the 1st token, expected: '1', found: '0' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3085 ms |
8024 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3085 ms |
8024 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4952 KB |
Output is correct |
2 |
Incorrect |
2 ms |
4952 KB |
1st lines differ - on the 1st token, expected: '52130940', found: '218061342' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4952 KB |
Output is correct |
2 |
Incorrect |
4 ms |
4952 KB |
1st lines differ - on the 1st token, expected: '1', found: '0' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4952 KB |
Output is correct |
2 |
Incorrect |
4 ms |
4952 KB |
1st lines differ - on the 1st token, expected: '1', found: '0' |
3 |
Halted |
0 ms |
0 KB |
- |