#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]]));
}
const int maxn = 100000;
bool lazy[4 * maxn];
long long sum[4 * maxn], st[4 * maxn];
void build(int v, int tl, int tr) {
if(tl == tr) {
sum[v] = val[tl];
if(stat[tr]) st[v] = sum[v];
return;
}
int tm =(tl + tr) / 2;
build(2 * v + 1, tl, tm);
build(2 * v + 2, tm + 1, tr);
sum[v] = ADD(sum[2 * v + 1], sum[2 * v + 2]);
st[v] = ADD(st[2 * v + 1], st[2 * v + 2]);
}
void update(int v, int tl, int tr, int l, int r) {
if(tl == l && tr == r) {
lazy[v] ^= true;
st[v] = SUB(sum[v], st[v]);
return;
}
int tm = (tl + tr) / 2;
if(lazy[v]) {
lazy[v] = false;
lazy[2 * v + 1] ^= true;
st[2 * v + 1] = SUB(sum[2 * v + 1], st[2 * v + 1]);
lazy[2 * v + 2] ^= true;
st[2 * v + 2] = SUB(sum[2 * v + 2], st[2 * v + 2]);
}
if(r <= tm) {
update(2 * v + 1, tl, tm, l, r);
} else if(l > tm) {
update(2 * v + 2, tm + 1, tr, l, r);
} else {
update(2 * v + 1, tl, tm, l, tm);
update(2 * v + 2, tm + 1, tr, tm + 1, tr);
}
st[v] = ADD(st[2 * v + 1], st[2 * v + 2]);
}
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]);
}
// build(0, 0, M - 1);
}
int count_ways(int L, int R) {
for(L -= N, R -= N; L <= R; ++L) {
if(stat[L]) ans = SUB(ans, val[L]);
else ans = ADD(ans, val[L]);
stat[L] = stat[L] ^ true;
}
return ans;
// return st[0];
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Execution timed out |
3060 ms |
208 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
464 KB |
Output is correct |
11 |
Correct |
1 ms |
464 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Execution timed out |
3060 ms |
208 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
591 ms |
4512 KB |
Output is correct |
2 |
Correct |
727 ms |
8572 KB |
Output is correct |
3 |
Correct |
661 ms |
8532 KB |
Output is correct |
4 |
Correct |
713 ms |
8532 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
591 ms |
4512 KB |
Output is correct |
2 |
Correct |
727 ms |
8572 KB |
Output is correct |
3 |
Correct |
661 ms |
8532 KB |
Output is correct |
4 |
Correct |
713 ms |
8532 KB |
Output is correct |
5 |
Execution timed out |
3034 ms |
4432 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
464 KB |
Output is correct |
11 |
Correct |
1 ms |
464 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
591 ms |
4512 KB |
Output is correct |
14 |
Correct |
727 ms |
8572 KB |
Output is correct |
15 |
Correct |
661 ms |
8532 KB |
Output is correct |
16 |
Correct |
713 ms |
8532 KB |
Output is correct |
17 |
Execution timed out |
3034 ms |
4432 KB |
Time limit exceeded |
18 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Execution timed out |
3060 ms |
208 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Execution timed out |
3060 ms |
208 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |