#include<bits/stdc++.h>
#define pb push_back
#define int long long
using namespace std;
#include "circuit.h"
const int M = 2000;
vector<int> state(M);
vector<int> ch[2 * M];
int n;
pair<int, int> dfs(int node){ // {kac sekilde 0, kac sekilde 1}
if(node >= n){
if(state[node - n]) return {0, 1};
else return {1, 0};
}
vector<pair<int, int> > sub;
int c = ch[node].size();
for(auto itr: ch[node]){
sub.pb(dfs(itr));
}
vector<int> dp(c+1), ndp(c+1);
dp[0] = 1;
for(auto itr: sub){
for(int i = 0; i <= c; i++){
ndp[i] = dp[i] * itr.first;
}
for(int i = 1; i <= c; i++){
ndp[i] += dp[i-1] * itr.second;
}
dp = ndp;
}
pair<int, int> val;
for(int i = 1; i <= c; i++){
for(int j = 1; j <= c; j++){
if(i > j) val.first += dp[j];
else val.second += dp[j];
}
}
return val;
}
void init(int N, int M, std::vector<int> P, std::vector<int> A) {
n = N;
for(int i = 1; i < N + M; i++){
ch[P[i]].pb(i);
}
for(int i = 0; i < M; i++) state[i] = A[i];
return;
}
int count_ways(int L, int R) {
L -= n;
R -= n;
for(int i = L; i <= R; i++){
state[i] ^= 1;
}
pair<int, int> ans = dfs(0);
return ans.second;
}
/*
int main() {
int N, M, Q;
assert(3 == scanf("%d %d %d", &N, &M, &Q));
std::vector<int> P(N + M), A(M);
for (int i = 0; i < N + M; ++i) {
assert(1 == scanf("%d", &P[i]));
}
for (int j = 0; j < M; ++j) {
assert(1 == scanf("%d", &A[j]));
}
init(N, M, P, A);
for (int i = 0; i < Q; ++i) {
int L, R;
assert(2 == scanf("%d %d", &L, &R));
printf("%d\n", count_ways(L, R));
}
return 0;
}
*/
Compilation message
/usr/bin/ld: /tmp/ccB1qnbI.o: in function `main':
stub.cpp:(.text.startup+0x128): undefined reference to `init(int, int, std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >)'
/usr/bin/ld: stub.cpp:(.text.startup+0x169): undefined reference to `count_ways(int, int)'
collect2: error: ld returned 1 exit status