#include "circuit.h"
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int y = 1000002022;
int n, m;
vector<int> p, a;
vector<vector<int>> g;
vector<ll> cw, aw;
ll fcw(int x){
if (x >= n) return cw[x] = a[x-n];
//cout << x << " " << g[x].size() << "\n";
//cout << fcw(g[x][0]) << " " << fcw(g[x][1]) << " " << aw[g[x][0]] << " " << aw[g[x][1]] << "\n";
return cw[x] = (((fcw(g[x][0])*aw[g[x][1]]) % y) + ((fcw(g[x][1])*aw[g[x][0]] % y)) % y);
}
ll faw(int x){
//cout << x << "\n";
if (x >= n) return aw[x] = 1;
ll res = g[x].size();
for (int next : g[x]) res = (res*faw(next)) % y;
return aw[x] = res;
}
void init(int N, int M, vector<int> P, vector<int> A){
n = N;
m = M;
p = P;
a = A;
g.resize(N);
for (int i=1; i<N+M; i++) g[p[i]].push_back(i);
cw.resize(N+M);
aw.resize(N+M);
faw(0);
}
int count_ways(int L, int R){
for (int i=L; i<=R; i++) a[i-n] = 1-a[i-n];
int f = 0;
for (int i=0; i<m; i++){
if (a[i]) f++;
}
return f;
/*for (int i=0; i<m; i++) cout << a[i] << " ";
cout << "\n";*/
/*fcw(0);
for (int i=0; i<n+m; i++) cout << aw[i] << " ";
cout << "\n";
for (int i=0; i<n+m; i++) cout << cw[i] << " ";
cout << "\n";
return cw[0];*/
return fcw(0);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Incorrect |
0 ms |
344 KB |
1st lines differ - on the 1st token, expected: '52130940', found: '128' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Incorrect |
0 ms |
344 KB |
1st lines differ - on the 1st token, expected: '52130940', found: '128' |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1385 ms |
4440 KB |
1st lines differ - on the 1st token, expected: '431985922', found: '16402' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1385 ms |
4440 KB |
1st lines differ - on the 1st token, expected: '431985922', found: '16402' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Incorrect |
0 ms |
344 KB |
1st lines differ - on the 1st token, expected: '52130940', found: '128' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Incorrect |
0 ms |
344 KB |
1st lines differ - on the 1st token, expected: '52130940', found: '128' |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Incorrect |
0 ms |
344 KB |
1st lines differ - on the 1st token, expected: '52130940', found: '128' |
11 |
Halted |
0 ms |
0 KB |
- |