#include "circuit.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i,x,y) for(ll i=x; i<y; i++)
#define FORNEG(i,x,y) for(ll i=x; i>y; i--)
const ll maxn = 100005;
vector<ll> edges[maxn];
ll sub[maxn];
ll realsub[maxn];
ll par[maxn];
void dfs(ll a){
if (edges[a].size()==0) sub[a] = 1;
else sub[a] = 0;
realsub[a] = 0;
for (auto&i : edges[a]){
dfs(i);
sub[a] += sub[i];
if (sub[i]!=1) realsub[a] += sub[i];
}
}
ll cache[maxn];
ll dp(ll a){
if (cache[a] != -1) return cache[a];
if (a==0) return 1;
cache[a] = dp(par[a]) * max((ll)1,(realsub[par[a]] - sub[a] * (sub[a] != 1))) % 1000002022;
return cache[a]% 1000002022;
}
ll states[maxn];
ll ans = 0;
void init(int N, int M, std::vector<int> P, std::vector<int> A) {
FOR(i,0,maxn) cache[i] = -1;
par[0] = -1;
FOR(i,1,N+M){
edges[P[i]].push_back(i);
par[i] = P[i];
}
dfs(0);
FOR(i,0,M){
states[N+i] = A[i];
if (A[i]==1) ans += dp(par[N+i]);
ans %= 1000002022;
}
}
int count_ways(int L, int R) {
FOR(i,L,R+1){
if (states[i]==1){
states[i] = 0;
ans -= dp(par[i]);
}else{
states[i] = 1;
ans += dp(par[i]);
}
ans %= 1000002022;
}
return (ans+1000002022)%1000002022;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
6488 KB |
Output is correct |
2 |
Correct |
1 ms |
6488 KB |
Output is correct |
3 |
Correct |
2 ms |
6488 KB |
Output is correct |
4 |
Correct |
2 ms |
6488 KB |
Output is correct |
5 |
Correct |
2 ms |
6488 KB |
Output is correct |
6 |
Correct |
1 ms |
6488 KB |
Output is correct |
7 |
Correct |
2 ms |
6488 KB |
Output is correct |
8 |
Correct |
2 ms |
6488 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
6488 KB |
Output is correct |
2 |
Incorrect |
2 ms |
6488 KB |
1st lines differ - on the 1st token, expected: '52130940', found: '359669620' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
6488 KB |
Output is correct |
2 |
Correct |
1 ms |
6488 KB |
Output is correct |
3 |
Correct |
2 ms |
6488 KB |
Output is correct |
4 |
Correct |
2 ms |
6488 KB |
Output is correct |
5 |
Correct |
2 ms |
6488 KB |
Output is correct |
6 |
Correct |
1 ms |
6488 KB |
Output is correct |
7 |
Correct |
2 ms |
6488 KB |
Output is correct |
8 |
Correct |
2 ms |
6488 KB |
Output is correct |
9 |
Correct |
2 ms |
6488 KB |
Output is correct |
10 |
Incorrect |
2 ms |
6488 KB |
1st lines differ - on the 1st token, expected: '52130940', found: '359669620' |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
476 ms |
8280 KB |
1st lines differ - on the 1st token, expected: '431985922', found: '137616072' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
476 ms |
8280 KB |
1st lines differ - on the 1st token, expected: '431985922', found: '137616072' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
6488 KB |
Output is correct |
2 |
Incorrect |
2 ms |
6488 KB |
1st lines differ - on the 1st token, expected: '52130940', found: '359669620' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
6488 KB |
Output is correct |
2 |
Correct |
1 ms |
6488 KB |
Output is correct |
3 |
Correct |
2 ms |
6488 KB |
Output is correct |
4 |
Correct |
2 ms |
6488 KB |
Output is correct |
5 |
Correct |
2 ms |
6488 KB |
Output is correct |
6 |
Correct |
1 ms |
6488 KB |
Output is correct |
7 |
Correct |
2 ms |
6488 KB |
Output is correct |
8 |
Correct |
2 ms |
6488 KB |
Output is correct |
9 |
Correct |
2 ms |
6488 KB |
Output is correct |
10 |
Incorrect |
2 ms |
6488 KB |
1st lines differ - on the 1st token, expected: '52130940', found: '359669620' |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
6488 KB |
Output is correct |
2 |
Correct |
1 ms |
6488 KB |
Output is correct |
3 |
Correct |
2 ms |
6488 KB |
Output is correct |
4 |
Correct |
2 ms |
6488 KB |
Output is correct |
5 |
Correct |
2 ms |
6488 KB |
Output is correct |
6 |
Correct |
1 ms |
6488 KB |
Output is correct |
7 |
Correct |
2 ms |
6488 KB |
Output is correct |
8 |
Correct |
2 ms |
6488 KB |
Output is correct |
9 |
Correct |
2 ms |
6488 KB |
Output is correct |
10 |
Incorrect |
2 ms |
6488 KB |
1st lines differ - on the 1st token, expected: '52130940', found: '359669620' |
11 |
Halted |
0 ms |
0 KB |
- |