#include "circuit.h"
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000002022;
int ckadd(int a, int b) {
return a + b >= MOD ? a + b - MOD : a + b;
}
int ckmul(int a, int b) {
return a * 1LL * b % MOD;
}
int ckpower(int a, int n) {
int res = 1;
while (n) {
if (n & 1)
res = ckmul(res, a);
a = ckmul(a, a);
n >>= 1;
}
return res;
}
int ckdiv(int a, int b) {
return ckmul(a, ckpower(b, MOD - 2));
}
const int N = (int)2e5 + 6;
int n, m;
int a[N];
int par[N];
int deg[N];
int ANS[N];
bool vis[N];
int solve(int v) {
for (int i = 0; i < n; i++) vis[i] = false;
while (v != -1) {
if (v < n) vis[v] = true;
v = par[v];
}
int prod = 1;
for (int i = 0; i < n; i++) if (!vis[i]) {
prod = ckmul(prod, deg[i]);
}
return prod;
}
void init(int N, int M, std::vector<int> P, std::vector<int> A) {
n = N;
m = M;
for (int i = n; i < n + m; i++) a[i] = A[i];
for (int i = 0; i < n + m; i++) par[i] = P[i];
for (int i = 1; i < n + m; i++) deg[par[i]]++;
for (int i = n; i < n + m; i++) ANS[i] = solve(i);
// for (int i = n; i < n + m; i++) printf("%d ", ANS[i]); printf("\n");
}
int count_ways(int L, int R) {
for (int i = L; i <= R; i++) a[i] ^= 1;
int ans = 0;
for (int i = n; i < n + m; i++) if (a[i] == 1) {
ans = ckadd(ans, ANS[i]);
}
return ans;
}
/*
3 4 3
-1 0 1 2 1 1 0
1 0 1 0
3 4
4 5
3 6
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
300 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Incorrect |
1 ms |
336 KB |
4th lines differ - on the 1st token, expected: '500', found: '504' |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Incorrect |
1 ms |
208 KB |
1st lines differ - on the 1st token, expected: '52130940', found: '844566252' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
300 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Incorrect |
1 ms |
336 KB |
4th lines differ - on the 1st token, expected: '500', found: '504' |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3047 ms |
1784 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3047 ms |
1784 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Incorrect |
1 ms |
208 KB |
1st lines differ - on the 1st token, expected: '52130940', found: '844566252' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
300 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Incorrect |
1 ms |
336 KB |
4th lines differ - on the 1st token, expected: '500', found: '504' |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
300 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Incorrect |
1 ms |
336 KB |
4th lines differ - on the 1st token, expected: '500', found: '504' |
4 |
Halted |
0 ms |
0 KB |
- |