#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
pair<int, int> pii;
const int MOD = 1000002022;
const int maxn = 2e5 + 100;
int n, k;
int p[maxn];
vector<int> g[maxn];
int a[maxn];
int t[maxn * 4];
ll sum[maxn];
ll d[2][maxn * 4];
ll dp[maxn];
void pre(int v){
swap(d[0][v], d[1][v]);
t[v] ^= 1;
}
void push(int v, int tl, int tr){
if(tl == tr || !t[v]) return;
t[v] = 0; pre(v<<1); pre(v<<1|1);
}
void build(int v = 1, int tl = k + 1, int tr = n){
if(tl == tr){
d[a[tl]][v] = dp[tl];
} else{
int mid = (tl + tr) >> 1;
build(v<<1, tl, mid);
build(v<<1|1, mid+1, tr);
d[0][v] = d[0][v<<1] + d[0][v<<1|1] % MOD;
d[1][v] = d[1][v<<1] + d[1][v<<1|1] % MOD;
}
}
void upd(int l, int r, int v = 1, int tl = k + 1, int tr = n){
push(v, tl, tr);
if(tl > r || tr < l) return;
if(l <= tl && tr <= r) pre(v);
else{
int mid = (tl + tr) >> 1;
upd(l, r, v<<1, tl, mid);
upd(l, r, v<<1|1, mid+1, tr);
d[0][v] = d[0][v<<1] + d[0][v<<1|1] % MOD;
d[1][v] = d[1][v<<1] + d[1][v<<1|1] % MOD;
}
}
void init(int N, int M, std::vector<int> P, std::vector<int> A){
n = N + M; k = N;
for(int i = 1; i <= n; i++){
p[i] = P[i-1]; p[i]++;
g[p[i]].push_back(i);
dp[i] = 1;
}
for(int v = n; v > 0; v--){
sum[v] = 1;
for(int to: g[v]){
sum[v] = sum[v] * sum[to] % MOD;
}
if(v <= k) sum[v] = sum[v] * g[v].size() % MOD;
}
for(int i = k + 1; i <= n; i++){
a[i] = A[i - k - 1];
}
for(int v = 1; v <= k; v++){
ll d = 1;
for(int to: g[v]){
dp[to] = dp[v];
dp[to] = dp[to] * d % MOD;
d = d * sum[to] % MOD;
}
d = 1;
reverse(g[v].begin(), g[v].end());
for(int to: g[v]){
dp[to] = dp[to] * d % MOD;
d = d * sum[to] % MOD;
}
}
build();
}
int count_ways(int L, int R){
upd(L + 1, R + 1);
return d[1][1];
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
10584 KB |
Output is correct |
2 |
Correct |
2 ms |
12632 KB |
Output is correct |
3 |
Correct |
2 ms |
12632 KB |
Output is correct |
4 |
Correct |
2 ms |
10584 KB |
Output is correct |
5 |
Correct |
1 ms |
10584 KB |
Output is correct |
6 |
Correct |
1 ms |
10584 KB |
Output is correct |
7 |
Correct |
2 ms |
10584 KB |
Output is correct |
8 |
Correct |
2 ms |
12632 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
10584 KB |
Output is correct |
2 |
Incorrect |
2 ms |
12756 KB |
1st lines differ - on the 1st token, expected: '52130940', found: '-1242830290' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
10584 KB |
Output is correct |
2 |
Correct |
2 ms |
12632 KB |
Output is correct |
3 |
Correct |
2 ms |
12632 KB |
Output is correct |
4 |
Correct |
2 ms |
10584 KB |
Output is correct |
5 |
Correct |
1 ms |
10584 KB |
Output is correct |
6 |
Correct |
1 ms |
10584 KB |
Output is correct |
7 |
Correct |
2 ms |
10584 KB |
Output is correct |
8 |
Correct |
2 ms |
12632 KB |
Output is correct |
9 |
Correct |
1 ms |
10584 KB |
Output is correct |
10 |
Incorrect |
2 ms |
12756 KB |
1st lines differ - on the 1st token, expected: '52130940', found: '-1242830290' |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
443 ms |
15192 KB |
1st lines differ - on the 1st token, expected: '431985922', found: '1137028736' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
443 ms |
15192 KB |
1st lines differ - on the 1st token, expected: '431985922', found: '1137028736' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
10584 KB |
Output is correct |
2 |
Incorrect |
2 ms |
12756 KB |
1st lines differ - on the 1st token, expected: '52130940', found: '-1242830290' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
10584 KB |
Output is correct |
2 |
Correct |
2 ms |
12632 KB |
Output is correct |
3 |
Correct |
2 ms |
12632 KB |
Output is correct |
4 |
Correct |
2 ms |
10584 KB |
Output is correct |
5 |
Correct |
1 ms |
10584 KB |
Output is correct |
6 |
Correct |
1 ms |
10584 KB |
Output is correct |
7 |
Correct |
2 ms |
10584 KB |
Output is correct |
8 |
Correct |
2 ms |
12632 KB |
Output is correct |
9 |
Correct |
1 ms |
10584 KB |
Output is correct |
10 |
Incorrect |
2 ms |
12756 KB |
1st lines differ - on the 1st token, expected: '52130940', found: '-1242830290' |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
10584 KB |
Output is correct |
2 |
Correct |
2 ms |
12632 KB |
Output is correct |
3 |
Correct |
2 ms |
12632 KB |
Output is correct |
4 |
Correct |
2 ms |
10584 KB |
Output is correct |
5 |
Correct |
1 ms |
10584 KB |
Output is correct |
6 |
Correct |
1 ms |
10584 KB |
Output is correct |
7 |
Correct |
2 ms |
10584 KB |
Output is correct |
8 |
Correct |
2 ms |
12632 KB |
Output is correct |
9 |
Correct |
1 ms |
10584 KB |
Output is correct |
10 |
Incorrect |
2 ms |
12756 KB |
1st lines differ - on the 1st token, expected: '52130940', found: '-1242830290' |
11 |
Halted |
0 ms |
0 KB |
- |