#include<bits/stdc++.h>
#define pb push_back
using namespace std;
#include "circuit.h"
#define ll long long
const int M = 2000;
int mod = 10121101010;
int add(ll a, ll b){
return ((a%mod) + (b%mod))%mod;
}
int mul(ll a, ll b){
return ((a%mod) * (b%mod))%mod;
}
vector<int> state(M);
vector<int> ch[2 * M];
int n;
pair<int, int> dfs(int node){ // {kac sekilde 0, kac sekilde 1}
if(node >= n){
if(state[node - n]) return {0, 1};
else return {1, 0};
}
vector<pair<int, int> > sub;
int c = ch[node].size();
for(auto itr: ch[node]){
sub.pb(dfs(itr));
}
vector<ll> dp(c+1), ndp(c+1);
dp[0] = 1;
for(auto itr: sub){
for(int i = 0; i <= c; i++){
ndp[i] = mul(dp[i], itr.first);
if(i) ndp[i] = add(ndp[i], mul(dp[i-1], itr.second));
}
dp = ndp;
}
pair<ll, ll> val;
for(int i = 1; i <= c; i++){
for(int j = 0; j <= c; j++){
if(i > j) val.first = add(val.first, dp[j]);
else val.second = add(val.second, dp[j]);
}
}
return val;
}
void init(int N, int M, std::vector<int> P, std::vector<int> A) {
n = N;
for(int i = 1; i < N + M; i++){
ch[P[i]].pb(i);
}
for(int i = 0; i < M; i++) state[i] = A[i];
return;
}
int count_ways(int L, int R) {
L -= n;
R -= n;
for(int i = L; i <= R; i++){
state[i] ^= 1;
}
pair<ll, ll> ans = dfs(0);
return ans.second;
}
Compilation message
circuit.cpp:9:11: warning: overflow in conversion from 'long int' to 'int' changes value from '10121101010' to '1531166418' [-Woverflow]
9 | int mod = 10121101010;
| ^~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
86 ms |
344 KB |
Output is correct |
4 |
Correct |
91 ms |
568 KB |
Output is correct |
5 |
Correct |
91 ms |
568 KB |
Output is correct |
6 |
Correct |
93 ms |
344 KB |
Output is correct |
7 |
Correct |
105 ms |
344 KB |
Output is correct |
8 |
Correct |
100 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: '61994290' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
86 ms |
344 KB |
Output is correct |
4 |
Correct |
91 ms |
568 KB |
Output is correct |
5 |
Correct |
91 ms |
568 KB |
Output is correct |
6 |
Correct |
93 ms |
344 KB |
Output is correct |
7 |
Correct |
105 ms |
344 KB |
Output is correct |
8 |
Correct |
100 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: '61994290' |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
10 ms |
2500 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
10 ms |
2500 KB |
Execution killed with signal 11 |
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: '61994290' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
86 ms |
344 KB |
Output is correct |
4 |
Correct |
91 ms |
568 KB |
Output is correct |
5 |
Correct |
91 ms |
568 KB |
Output is correct |
6 |
Correct |
93 ms |
344 KB |
Output is correct |
7 |
Correct |
105 ms |
344 KB |
Output is correct |
8 |
Correct |
100 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: '61994290' |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
86 ms |
344 KB |
Output is correct |
4 |
Correct |
91 ms |
568 KB |
Output is correct |
5 |
Correct |
91 ms |
568 KB |
Output is correct |
6 |
Correct |
93 ms |
344 KB |
Output is correct |
7 |
Correct |
105 ms |
344 KB |
Output is correct |
8 |
Correct |
100 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: '61994290' |
11 |
Halted |
0 ms |
0 KB |
- |