#include "circuit.h"
#include <vector>
#include <bits/stdc++.h>
using namespace std;
#define ar array
#define pb push_back
#define ln '\n'
const int Mod = 1000002022;
vector <int> a;
vector <vector<int>> adj;
vector <int> dp;
int n, m;
template <class F, class S>
void add(F &x, const S &y){
x = (x + 0LL + y) % Mod;
if ( x < 0 ) x += Mod;
}
void init(int N, int M, std::vector<int> P, std::vector<int> A) {
a = A, n = N, m = M;
adj.resize(n + m);
for ( int i = 1; i < n + m; i++ ){
adj[P[i]].pb(i);
}
vector <int> s(n + m);
dp.resize(m);
auto dfs = [&](auto dfs, int u, int cnt) -> void{
if ( u >= n ){
dp[u - n] = cnt;
return;
}
int s = adj[u].size();
vector <int> child, vl;
for ( auto &v: adj[u] ){
int x = adj[v].size();
child.pb(v); vl.pb(max(1, x));
}
vector <int> pf(s + 1, 1), sf(s + 2, 1);
for ( int i = 0; i < s; i++ ){
pf[i + 1] = pf[i] * 1LL * vl[i] % Mod;
}
for ( int i = s; i > 0; i-- ){
sf[i] = sf[i + 1] * 1LL * vl[i - 1] % Mod;
}
for ( int i = 0; i < s; i++ ){
int nxt = cnt * 1LL * pf[i] % Mod * sf[i + 2] % Mod;
dfs(dfs, child[i], nxt);
}
};
dfs(dfs, 0, 1);
}
int count_ways(int L, int R) {
L -= n, R -= n;
int cnt = 0;
for ( int i = L; i <= R; i++ ){
a[i] ^= 1;
}
for ( int i = 0; i < m; i++ ){
add(cnt, a[i] * dp[i]);
}
return cnt;
}
# |
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 |
0 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 |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
0 ms |
344 KB |
1st lines differ - on the 1st token, expected: '52130940', found: '16384' |
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 |
0 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 |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Incorrect |
0 ms |
344 KB |
1st lines differ - on the 1st token, expected: '52130940', found: '16384' |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3032 ms |
4184 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3032 ms |
4184 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
0 ms |
344 KB |
1st lines differ - on the 1st token, expected: '52130940', found: '16384' |
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 |
0 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 |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Incorrect |
0 ms |
344 KB |
1st lines differ - on the 1st token, expected: '52130940', found: '16384' |
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 |
0 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 |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Incorrect |
0 ms |
344 KB |
1st lines differ - on the 1st token, expected: '52130940', found: '16384' |
11 |
Halted |
0 ms |
0 KB |
- |