#include "circuit.h"
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define FOR(i, x, y) for(ll i=x; i<y; i++)
#define FORNEG(i, x, y) for(ll i=x; i>y; i--)
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL)
vector<ll> edges[100001];
ll possible[100001];
ll contrib[100001];
bool state[100001];
int initdfs(ll a){
if (edges[a].size() == 0) return possible[a] = 1;
ll temp = 1;
for (auto&i : edges[a]){
temp *= initdfs(i);
temp %= 1000002022;
}
temp *= edges[a].size();
temp %= 1000002022;
return possible[a] = temp;
}
ll n,m;
void init(int N, int M, std::vector<int> P, std::vector<int> A) {
n = N;
m = M;
FOR(i,1,N+M){
edges[P[i]].push_back(i);
}
FOR(i,N,N+M){
state[i] = A[i-N];
}
initdfs(0);
FOR(i,N,N+M){
ll temp = 1;
ll cur = i;
while (cur != 0){
temp *= (possible[P[cur]] / possible[cur] ) / edges[P[cur]].size();
temp %= 1000002022;
cur = P[cur];
}
contrib[i] = temp%1000002022;
}
}
int count_ways(int L, int R) {
FOR(i,L,R+1){
state[i] = (state[i]+1)%2;
}
ll ans = 0;
FOR(i,n,n+m){
if (state[i]) ans += contrib[i];
}
return ans%1000002022;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2640 KB |
Output is correct |
2 |
Correct |
2 ms |
2640 KB |
Output is correct |
3 |
Correct |
2 ms |
2584 KB |
Output is correct |
4 |
Correct |
2 ms |
2640 KB |
Output is correct |
5 |
Correct |
1 ms |
2640 KB |
Output is correct |
6 |
Correct |
2 ms |
2640 KB |
Output is correct |
7 |
Correct |
1 ms |
2640 KB |
Output is correct |
8 |
Correct |
2 ms |
2640 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2640 KB |
Output is correct |
2 |
Incorrect |
2 ms |
2640 KB |
1st lines differ - on the 1st token, expected: '52130940', found: '0' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2640 KB |
Output is correct |
2 |
Correct |
2 ms |
2640 KB |
Output is correct |
3 |
Correct |
2 ms |
2584 KB |
Output is correct |
4 |
Correct |
2 ms |
2640 KB |
Output is correct |
5 |
Correct |
1 ms |
2640 KB |
Output is correct |
6 |
Correct |
2 ms |
2640 KB |
Output is correct |
7 |
Correct |
1 ms |
2640 KB |
Output is correct |
8 |
Correct |
2 ms |
2640 KB |
Output is correct |
9 |
Correct |
1 ms |
2640 KB |
Output is correct |
10 |
Incorrect |
2 ms |
2640 KB |
1st lines differ - on the 1st token, expected: '52130940', found: '0' |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3053 ms |
5216 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3053 ms |
5216 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2640 KB |
Output is correct |
2 |
Incorrect |
2 ms |
2640 KB |
1st lines differ - on the 1st token, expected: '52130940', found: '0' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2640 KB |
Output is correct |
2 |
Correct |
2 ms |
2640 KB |
Output is correct |
3 |
Correct |
2 ms |
2584 KB |
Output is correct |
4 |
Correct |
2 ms |
2640 KB |
Output is correct |
5 |
Correct |
1 ms |
2640 KB |
Output is correct |
6 |
Correct |
2 ms |
2640 KB |
Output is correct |
7 |
Correct |
1 ms |
2640 KB |
Output is correct |
8 |
Correct |
2 ms |
2640 KB |
Output is correct |
9 |
Correct |
1 ms |
2640 KB |
Output is correct |
10 |
Incorrect |
2 ms |
2640 KB |
1st lines differ - on the 1st token, expected: '52130940', found: '0' |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2640 KB |
Output is correct |
2 |
Correct |
2 ms |
2640 KB |
Output is correct |
3 |
Correct |
2 ms |
2584 KB |
Output is correct |
4 |
Correct |
2 ms |
2640 KB |
Output is correct |
5 |
Correct |
1 ms |
2640 KB |
Output is correct |
6 |
Correct |
2 ms |
2640 KB |
Output is correct |
7 |
Correct |
1 ms |
2640 KB |
Output is correct |
8 |
Correct |
2 ms |
2640 KB |
Output is correct |
9 |
Correct |
1 ms |
2640 KB |
Output is correct |
10 |
Incorrect |
2 ms |
2640 KB |
1st lines differ - on the 1st token, expected: '52130940', found: '0' |
11 |
Halted |
0 ms |
0 KB |
- |