#include <bits/stdc++.h>
#include "circuit.h"
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define ALL(v) (v).begin(), (v).end()
#define MASK(i) (1LL << (i))
#define GETBIT(mask, i) (((mask) >> (i)) & 1)
// mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rng(1);
ll rngesus(ll l, ll r){return ((ull) rng()) % (r - l + 1) + l;}
ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}
ll LASTBIT(ll mask){return mask & (-mask);}
ll pop_cnt(ll mask){return __builtin_popcountll(mask);}
ll ctz(ll mask){return __builtin_ctzll(mask);}
ll clz(ll mask){return __builtin_clzll(mask);}
ll logOf(ll mask){return 63 - clz(mask);}
template <class T1, class T2>
bool minimize(T1 &a, T2 b){
if (a > b){a = b; return true;}
return false;
}
template <class T1, class T2>
bool maximize(T1 &a, T2 b){
if (a < b){a = b; return true;}
return false;
}
template <class T>
void printArr(T& a, string separator = " ", string finish = "\n", ostream& out = cout){
for(auto i: a) out << i << separator;
out << finish;
}
template <class T>
void remove_dup(vector<T> &a){
sort(ALL(a));
a.resize(unique(ALL(a)) - a.begin());
}
const int N = 2e5 + 69, MOD = 1e9 + 2022;
int n, m;
vector<int> graph[N];
int dp[N][2];
int prod[N];
void init(int _n, int _m, vector<int> P, vector<int> A) {
n = _n, m = _m;
for(int i = 1; i<n+m; ++i){
graph[P[i]].push_back(i);
}
for(int i = 0; i<m; ++i){
prod[i+n] = 1;
dp[i+n][A[i]] = 1;
}
}
void add(int &a, int b){
a += b;
if (a >= MOD) a -= MOD;
}
void sub(int &a, int b){
a -= b;
if (a < 0) a += MOD;
}
void go(int u, int p){
if (u >= n) return;
dp[u][0] = dp[u][1] = 0;
prod[u] = graph[u].size();
int sum = 1, pref = 1;
for(int v: graph[u]) if (v != p){
go(v, u);
pref = (1LL * pref * dp[v][0] + 1LL * (pref + sum) * dp[v][1]) % MOD;
sum = 1LL * sum * (dp[v][0] + dp[v][1]) % MOD;
prod[u] = prod[u] * prod[v] % MOD;
}
dp[u][1] = pref;
sub(dp[u][1], sum);
dp[u][0] = prod[u];
sub(dp[u][0], dp[u][1]);
}
int count_ways(int l, int r) {
for(int i = l; i <= r; ++i){
swap(dp[i][0], dp[i][1]);
}
go(0, 0);
return dp[0][1];
}
// int main(void){
// ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
// int n, m; cin >> n >> m;
// vector<int> P(n+m, -1);
// for(int i = 1; i<n+m; ++i) cin >> P[i];
// vector<int> A(m);
// for(int i = 0; i<m; ++i) cin >> A[i];
// init(n, m, P, A);
// int q; cin >> q;
// while(q--){
// int l, r; cin >> l >> r;
// cout << count_ways(l, r) << "\n";
// }
// return 0;
// }
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
7256 KB |
Output is correct |
2 |
Correct |
2 ms |
7256 KB |
Output is correct |
3 |
Correct |
2 ms |
7256 KB |
Output is correct |
4 |
Correct |
2 ms |
7256 KB |
Output is correct |
5 |
Correct |
2 ms |
7256 KB |
Output is correct |
6 |
Correct |
2 ms |
7092 KB |
Output is correct |
7 |
Correct |
2 ms |
7256 KB |
Output is correct |
8 |
Correct |
2 ms |
7508 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
7256 KB |
Output is correct |
2 |
Incorrect |
2 ms |
7256 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 |
3 ms |
7256 KB |
Output is correct |
2 |
Correct |
2 ms |
7256 KB |
Output is correct |
3 |
Correct |
2 ms |
7256 KB |
Output is correct |
4 |
Correct |
2 ms |
7256 KB |
Output is correct |
5 |
Correct |
2 ms |
7256 KB |
Output is correct |
6 |
Correct |
2 ms |
7092 KB |
Output is correct |
7 |
Correct |
2 ms |
7256 KB |
Output is correct |
8 |
Correct |
2 ms |
7508 KB |
Output is correct |
9 |
Correct |
4 ms |
7256 KB |
Output is correct |
10 |
Incorrect |
2 ms |
7256 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 |
3078 ms |
9048 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3078 ms |
9048 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
7256 KB |
Output is correct |
2 |
Incorrect |
2 ms |
7256 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 |
3 ms |
7256 KB |
Output is correct |
2 |
Correct |
2 ms |
7256 KB |
Output is correct |
3 |
Correct |
2 ms |
7256 KB |
Output is correct |
4 |
Correct |
2 ms |
7256 KB |
Output is correct |
5 |
Correct |
2 ms |
7256 KB |
Output is correct |
6 |
Correct |
2 ms |
7092 KB |
Output is correct |
7 |
Correct |
2 ms |
7256 KB |
Output is correct |
8 |
Correct |
2 ms |
7508 KB |
Output is correct |
9 |
Correct |
4 ms |
7256 KB |
Output is correct |
10 |
Incorrect |
2 ms |
7256 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 |
3 ms |
7256 KB |
Output is correct |
2 |
Correct |
2 ms |
7256 KB |
Output is correct |
3 |
Correct |
2 ms |
7256 KB |
Output is correct |
4 |
Correct |
2 ms |
7256 KB |
Output is correct |
5 |
Correct |
2 ms |
7256 KB |
Output is correct |
6 |
Correct |
2 ms |
7092 KB |
Output is correct |
7 |
Correct |
2 ms |
7256 KB |
Output is correct |
8 |
Correct |
2 ms |
7508 KB |
Output is correct |
9 |
Correct |
4 ms |
7256 KB |
Output is correct |
10 |
Incorrect |
2 ms |
7256 KB |
1st lines differ - on the 1st token, expected: '52130940', found: '971487268' |
11 |
Halted |
0 ms |
0 KB |
- |