#include "circuit.h"
#include "bits/stdc++.h"
using namespace std;
#define forR(i, x) for(int i = 0; i < (x); ++i)
#define REP(i, a, b) for(int i = (a); i < (b); ++i)
#define all(x) x.begin(), x.end()
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<bool> vb;
const ll MOD = 1000002022;
const int MN = 1e5 + 10;
vvi ch;
vll w;
int n, m;
vi totPos;
void sdfs(int c) {
totPos[c] = c >= n ? 1 : ch[c].size();
for(int i : ch[c]) {
sdfs(i);
totPos[c] = totPos[c] * totPos[i] % MOD;
}
}
void dfs(int c, ll cw) {
w[c] = cw;
for(int i : ch[c]) {
ll wCh = cw;
for(int j : ch[c]) if(j != i) wCh = wCh * totPos[j] % MOD;
dfs(i, wCh);
}
}
vb tgl;
void init(int N, int M, std::vector<int> P, std::vector<int> A) {
::n = N, ::m = M;
ch.resize(N+M);
totPos.resize(N+M);
w.resize(N+M);
tgl.resize(N+M);
REP(i, 1, N+M) ch[P[i]].push_back(i);
sdfs(0);
dfs(0, 1);
forR(i, M) tgl[N+i] = A[i] == 1;
}
ll gdp(int c) {
ll tot = c >= n ? tgl[c] == 1 ? 1 : 0 : 0;
for(int i : ch[c]) {
ll cont = gdp(i);
for(int j : ch[c]) if(j != i) cont = cont * totPos[j] % MOD;
tot = (tot + cont) % MOD;
}
return tot;
}
int count_ways(int L, int R) {
REP(i, L, R+1) tgl[i] = !tgl[i];
ll tot = 0;
REP(i, n, n+m) if(tgl[i]) tot = (w[i] + tot) % MOD;
return (int) gdp(0);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
20 ms |
480 KB |
Output is correct |
4 |
Correct |
22 ms |
484 KB |
Output is correct |
5 |
Correct |
22 ms |
604 KB |
Output is correct |
6 |
Correct |
22 ms |
492 KB |
Output is correct |
7 |
Correct |
22 ms |
344 KB |
Output is correct |
8 |
Correct |
22 ms |
344 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: '971487268' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
20 ms |
480 KB |
Output is correct |
4 |
Correct |
22 ms |
484 KB |
Output is correct |
5 |
Correct |
22 ms |
604 KB |
Output is correct |
6 |
Correct |
22 ms |
492 KB |
Output is correct |
7 |
Correct |
22 ms |
344 KB |
Output is correct |
8 |
Correct |
22 ms |
344 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: '971487268' |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3075 ms |
4440 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3075 ms |
4440 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: '971487268' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
20 ms |
480 KB |
Output is correct |
4 |
Correct |
22 ms |
484 KB |
Output is correct |
5 |
Correct |
22 ms |
604 KB |
Output is correct |
6 |
Correct |
22 ms |
492 KB |
Output is correct |
7 |
Correct |
22 ms |
344 KB |
Output is correct |
8 |
Correct |
22 ms |
344 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: '971487268' |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
20 ms |
480 KB |
Output is correct |
4 |
Correct |
22 ms |
484 KB |
Output is correct |
5 |
Correct |
22 ms |
604 KB |
Output is correct |
6 |
Correct |
22 ms |
492 KB |
Output is correct |
7 |
Correct |
22 ms |
344 KB |
Output is correct |
8 |
Correct |
22 ms |
344 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: '971487268' |
11 |
Halted |
0 ms |
0 KB |
- |