#include"circuit.h"
#include<bits/stdc++.h>
using namespace std;
const long long MOD = 1000002022;
long long MUL(long long A, long long B) {
return A * B % MOD;
}
long long ADD(long long A, long long B) {
A += B;
if(A >= MOD) A -= MOD;
return A;
}
long long SUB(long long A, long long B) {
return ADD(A, MOD - B);
}
int N, M;
vector<vector<int>> ch;
vector<int> par, stat;
vector<long long> sz, val;
long long ans;
void dfs(int s) {
if(ch[s].empty()) {
sz[s] = 1LL;
return;
}
sz[s] = 2LL;
for(auto& u : ch[s]) {
dfs(u);
sz[s] = MUL(sz[s], sz[u]);
}
}
void ass_val(int s, long long v) {
if(ch[s].empty()) { val[s - N] = v; return; }
ass_val(ch[s][0], MUL(v, sz[ch[s][1]]));
ass_val(ch[s][1], MUL(v, sz[ch[s][0]]));
}
void init(int _N, int _M, vector<int> P, vector<int> A) {
N = _N; M = _M;
swap(P, par);
swap(A, stat);
val.resize(M);
ch.resize(N + M);
sz.resize(N + M);
for(int i = 1; i < N + M; ++i) {
ch[par[i]].push_back(i);
}
dfs(0);
ass_val(0, 1LL);
for(int i = 0; i < M; ++i) {
if(stat[i]) ans = ADD(ans, val[i]);
}
}
int count_ways(int L, int R) {
L -= N;
if(stat[L]) ans = SUB(ans, val[L]);
else ans = ADD(ans, val[L]);
stat[L] = stat[L] ^ true;
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
208 KB |
3rd lines differ - on the 1st token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
208 KB |
3rd lines differ - on the 1st token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
208 KB |
3rd lines differ - on the 1st token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
525 ms |
4416 KB |
Output is correct |
2 |
Correct |
784 ms |
8528 KB |
Output is correct |
3 |
Correct |
627 ms |
8520 KB |
Output is correct |
4 |
Correct |
594 ms |
8528 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
525 ms |
4416 KB |
Output is correct |
2 |
Correct |
784 ms |
8528 KB |
Output is correct |
3 |
Correct |
627 ms |
8520 KB |
Output is correct |
4 |
Correct |
594 ms |
8528 KB |
Output is correct |
5 |
Incorrect |
586 ms |
4432 KB |
1st lines differ - on the 1st token, expected: '105182172', found: '2777846' |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
208 KB |
3rd lines differ - on the 1st token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
208 KB |
3rd lines differ - on the 1st token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
208 KB |
3rd lines differ - on the 1st token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |