#include "circuit.h"
#include <bits/stdc++.h>
using namespace std;
constexpr int mod = 1000002022;
int N, M;
vector<int> P, A;
vector<vector<int>> ch;
int add(int a, int b) {
int c = a + b;
if (c >= mod) {
c -= mod;
}
return c;
}
int mul(int a, int b) {
return 1LL * a * b % mod;
}
int sub(int a, int b) {
int c = a - b;
if (c < 0) {
c += mod;
}
return c;
}
int cnt, cont;
bool bintree;
void init(int n, int m, vector<int> p, vector<int> a) {
N = n, M = m;
P = p, A = a;
ch.resize(N);
for (int i = 1; i < N + M; i++) {
ch[P[i]].push_back(i);
}
bintree = 0;
if (N + 1 == M && __builtin_popcount(M) == 1) {
bintree = 1;
for (int i = 1; i < N + M; i++) {
if (P[i] != (i - 1) / 2) {
bintree = 0;
}
}
if (bintree) {
cnt = 0;
for (int i = 0; i < M; i++) {
cnt += A[i];
}
int lg = __lg(M);
cont = 1;
int s = 1;
for (int i = 0; i < lg; i++) {
cont = mul(cont, s);
s = mul(2, mul(s, s));
}
}
}
}
int count_ways(int L, int R) {
for (int i = L; i <= R; i++) {
A[i - N] ^= 1;
cnt += A[i - N] == 1 ? 1 : -1;
}
if (bintree) {
return mul(cnt, cont);
}
vector<int> tot(N + M), on(N + M), off(N + M);
for (int i = N + M - 1; i >= 0; i--) {
if (i >= N) {
tot[i] = 1;
if (A[i - N] == 0) {
off[i] = 1;
} else {
on[i] = 1;
}
} else {
int x = ch[i][0];
int y = ch[i][1];
tot[i] = mul(2, mul(tot[x], tot[y]));
on[i] = add(mul(tot[x], on[y]), mul(tot[y], on[x]));
off[i] = sub(tot[i], on[i]);
}
}
return on[0];
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Incorrect |
0 ms |
208 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 |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
208 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Incorrect |
0 ms |
208 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 |
524 ms |
3152 KB |
Output is correct |
2 |
Correct |
699 ms |
6184 KB |
Output is correct |
3 |
Correct |
640 ms |
6088 KB |
Output is correct |
4 |
Correct |
670 ms |
6184 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
524 ms |
3152 KB |
Output is correct |
2 |
Correct |
699 ms |
6184 KB |
Output is correct |
3 |
Correct |
640 ms |
6088 KB |
Output is correct |
4 |
Correct |
670 ms |
6184 KB |
Output is correct |
5 |
Correct |
2526 ms |
3152 KB |
Output is correct |
6 |
Execution timed out |
3073 ms |
6084 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
208 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
524 ms |
3152 KB |
Output is correct |
14 |
Correct |
699 ms |
6184 KB |
Output is correct |
15 |
Correct |
640 ms |
6088 KB |
Output is correct |
16 |
Correct |
670 ms |
6184 KB |
Output is correct |
17 |
Correct |
2526 ms |
3152 KB |
Output is correct |
18 |
Execution timed out |
3073 ms |
6084 KB |
Time limit exceeded |
19 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Incorrect |
0 ms |
208 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 |
0 ms |
208 KB |
Output is correct |
2 |
Incorrect |
0 ms |
208 KB |
1st lines differ - on the 1st token, expected: '1', found: '0' |
3 |
Halted |
0 ms |
0 KB |
- |