#include "circuit.h"
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define all(a) (a).begin(), (a).end()
#define ll long long
const int mod = 1000002022;
vector<int> state, p;
int n, m;
vector<vector<int>> g;
template<typename T>
int len(T &a){return a.size();}
vector<array<ll, 2>> dp;
vector<int> marked;
void build(int i){
if(i >= n){
dp[i][0] = state[i - n] ^ 1;
dp[i][1] = state[i - n];
return;
}
for(auto u : g[i]) build(u);
vector<ll> prep(len(g[i]) + 1);
prep[0] = 1;
ll al = len(g[i]);
int cur = 0;
for(auto u : g[i]){
cur ++;
al = al * (dp[u][0] + dp[u][1]) % mod;
for(int j = cur; j >= 0; j --){
prep[j] = prep[j] * dp[u][0] % mod;
if(j) prep[j] += prep[j - 1] * dp[u][1] % mod;
}
}
dp[i][1] = 0;
for(int j = 1; j <= len(g[i]); j ++){
dp[i][1] = (dp[i][1] + prep[j] * j) % mod;
}
dp[i][0] = al - dp[i][1];
if(dp[i][0] < 0) dp[i][0] += mod;
}
void push(int i){
if(!marked[i]) return;
marked[i] = 0;
int l = g[i][0], r = g[i][1];
swap(dp[l][0], dp[l][1]);
swap(dp[r][0], dp[r][1]);
marked[l] ^= 1;
marked[r] ^= 1;
}
void upd(int i, int l, int r, int ql, int qr){
if(l > ql || ql > r) return;
if(ql <= l && r <= qr){
swap(dp[i][0], dp[i][1]);
marked[i] ^= 1;
return;
}
push(i);
int m = (l + r) / 2;
upd(g[i][0], l, m, ql, qr);
upd(g[i][1], m + 1, r, ql, qr);
vector<ll> prep(len(g[i]) + 1);
prep[0] = 1;
ll al = len(g[i]);
int cur = 0;
for(auto u : g[i]){
cur ++;
al = al * (dp[u][0] + dp[u][1]) % mod;
for(int j = cur; j >= 0; j --){
prep[j] = prep[j] * dp[u][0] % mod;
if(j) prep[j] += prep[j - 1] * dp[u][1] % mod;
}
}
dp[i][1] = 0;
for(int j = 1; j <= len(g[i]); j ++){
dp[i][1] = (dp[i][1] + prep[j] * j) % mod;
}
dp[i][0] = al - dp[i][1];
if(dp[i][0] < 0) dp[i][0] += mod;
}
void init(int N, int M, std::vector<int> P, std::vector<int> A) {
n = N, m = M;
g.resize(n);
state = A;
p = P;
for(int i = 1; i < n + m; i ++){
g[p[i]].push_back(i);
}
dp.resize(n + m);
marked.resize(n + m);
build(0);
}
int count_ways(int l, int r){
upd(0, n, n + m - 1, l, r);
return dp[0][1];
}
# |
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 |
Runtime error |
2 ms |
600 KB |
Execution killed with signal 11 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Incorrect |
0 ms |
344 KB |
1st lines differ - on the 1st token, expected: '52130940', found: '474414066' |
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 |
Runtime error |
2 ms |
600 KB |
Execution killed with signal 11 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
483 ms |
4440 KB |
Output is correct |
2 |
Correct |
770 ms |
8792 KB |
Output is correct |
3 |
Correct |
744 ms |
9048 KB |
Output is correct |
4 |
Correct |
714 ms |
8792 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
483 ms |
4440 KB |
Output is correct |
2 |
Correct |
770 ms |
8792 KB |
Output is correct |
3 |
Correct |
744 ms |
9048 KB |
Output is correct |
4 |
Correct |
714 ms |
8792 KB |
Output is correct |
5 |
Incorrect |
560 ms |
4644 KB |
1st lines differ - on the 1st token, expected: '105182172', found: '114977558' |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Incorrect |
0 ms |
344 KB |
1st lines differ - on the 1st token, expected: '52130940', found: '474414066' |
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 |
Runtime error |
2 ms |
600 KB |
Execution killed with signal 11 |
4 |
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 |
Runtime error |
2 ms |
600 KB |
Execution killed with signal 11 |
4 |
Halted |
0 ms |
0 KB |
- |