#include "circuit.h"
#include<bits/stdc++.h>
using namespace std;
long long n,m;
vector<long long> p2(300001);
vector<long long> haha[300001];
vector<long long> st(300001);
vector<long long> wow(300001);
vector<long long> no(300001);
vector<long long> sum(800001);
vector<long long> idk(800001);
vector<long long> val(800001);
const long long MOD = 1e9+2022;
void build(long long l, long long r, long long x) {
if(l == r) {
sum[x] = wow[l+n];
if(no[l]) {
val[x] = sum[x];
}
else {
val[x] = 0;
}
idk[x] = 0;
return;
}
long long mid = (l+r)/2;
build(l,mid,x*2+1);
build(mid+1,r,x*2+2);
sum[x] = (sum[x*2+1]+sum[x*2+2])%MOD;
val[x] = (val[x*2+1]+val[x*2+2])%MOD;
}
void upd(long long l, long long r, long long ql, long long qr, long long x) {
if(l == ql && r == qr) {
idk[x]++;
idk[x]%=2;
val[x] = (sum[x]-val[x]+MOD)%MOD;
return;
}
long long mid = (l+r)/2;
if(qr <= mid) {
upd(l,mid,ql,qr,x*2+1);
}
else if(ql >= mid+1) {
upd(mid+1,r,ql,qr,x*2+2);
}
else {
upd(l,mid,ql,mid,x*2+1);
upd(mid+1,r,mid+1,qr,x*2+2);
}
val[x] = (val[x*2+1]+val[x*2+2])%MOD;
if(idk[x]%2) {
val[x] = (sum[x]-val[x]+MOD)%MOD;
}
}
void dfs(long long a) {
long long sb = 0;
if(a < n) {
sb = 1;
}
for(long long v: haha[a]) {
dfs(v);
sb+=st[v];
}
st[a] = sb;
}
void dude(long long a) {
if(!haha[a].empty()) {
wow[haha[a][0]] = wow[a]+st[haha[a][1]];
wow[haha[a][1]] = wow[a]+st[haha[a][0]];
dude(haha[a][0]);
dude(haha[a][1]);
}
}
void init(int N, int M, vector<int> p, vector<int> a) {
n = N;
m = M;
p2[0] = 1;
for(long long i = 1; i < 300000; i++) {
p2[i] = (p2[i-1]*2)%MOD;
}
for(long long i = 1; i < n+m; i++) {
haha[p[i]].push_back(i);
}
dfs(0);
dude(0);
for(int i = n; i < n+m; i++) {
wow[i] = p2[wow[i]];
}
for(int i = 0; i < a.size(); i++) {
no[i] = a[i];
}
build(0,m-1,0);
}
int count_ways(int l, int r) {
upd(0,m-1,l-n,r-n,0);
return val[0];
}
Compilation message
circuit.cpp: In function 'void init(int, int, std::vector<int>, std::vector<int>)':
circuit.cpp:95:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
95 | for(int i = 0; i < a.size(); i++) {
| ~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
35520 KB |
Output is correct |
2 |
Execution timed out |
3074 ms |
35428 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
35536 KB |
Output is correct |
2 |
Correct |
15 ms |
35496 KB |
Output is correct |
3 |
Correct |
15 ms |
35524 KB |
Output is correct |
4 |
Correct |
16 ms |
35536 KB |
Output is correct |
5 |
Correct |
15 ms |
35572 KB |
Output is correct |
6 |
Correct |
17 ms |
35560 KB |
Output is correct |
7 |
Correct |
15 ms |
35536 KB |
Output is correct |
8 |
Correct |
15 ms |
35560 KB |
Output is correct |
9 |
Correct |
16 ms |
35516 KB |
Output is correct |
10 |
Correct |
16 ms |
35652 KB |
Output is correct |
11 |
Correct |
16 ms |
35536 KB |
Output is correct |
12 |
Correct |
17 ms |
35524 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
35520 KB |
Output is correct |
2 |
Execution timed out |
3074 ms |
35428 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
597 ms |
37316 KB |
Output is correct |
2 |
Correct |
694 ms |
39112 KB |
Output is correct |
3 |
Correct |
596 ms |
39112 KB |
Output is correct |
4 |
Correct |
782 ms |
39108 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
597 ms |
37316 KB |
Output is correct |
2 |
Correct |
694 ms |
39112 KB |
Output is correct |
3 |
Correct |
596 ms |
39112 KB |
Output is correct |
4 |
Correct |
782 ms |
39108 KB |
Output is correct |
5 |
Correct |
645 ms |
37328 KB |
Output is correct |
6 |
Correct |
639 ms |
39116 KB |
Output is correct |
7 |
Correct |
803 ms |
39116 KB |
Output is correct |
8 |
Correct |
834 ms |
39120 KB |
Output is correct |
9 |
Correct |
387 ms |
35632 KB |
Output is correct |
10 |
Correct |
874 ms |
35720 KB |
Output is correct |
11 |
Correct |
630 ms |
35744 KB |
Output is correct |
12 |
Correct |
661 ms |
35764 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
35536 KB |
Output is correct |
2 |
Correct |
15 ms |
35496 KB |
Output is correct |
3 |
Correct |
15 ms |
35524 KB |
Output is correct |
4 |
Correct |
16 ms |
35536 KB |
Output is correct |
5 |
Correct |
15 ms |
35572 KB |
Output is correct |
6 |
Correct |
17 ms |
35560 KB |
Output is correct |
7 |
Correct |
15 ms |
35536 KB |
Output is correct |
8 |
Correct |
15 ms |
35560 KB |
Output is correct |
9 |
Correct |
16 ms |
35516 KB |
Output is correct |
10 |
Correct |
16 ms |
35652 KB |
Output is correct |
11 |
Correct |
16 ms |
35536 KB |
Output is correct |
12 |
Correct |
17 ms |
35524 KB |
Output is correct |
13 |
Correct |
597 ms |
37316 KB |
Output is correct |
14 |
Correct |
694 ms |
39112 KB |
Output is correct |
15 |
Correct |
596 ms |
39112 KB |
Output is correct |
16 |
Correct |
782 ms |
39108 KB |
Output is correct |
17 |
Correct |
645 ms |
37328 KB |
Output is correct |
18 |
Correct |
639 ms |
39116 KB |
Output is correct |
19 |
Correct |
803 ms |
39116 KB |
Output is correct |
20 |
Correct |
834 ms |
39120 KB |
Output is correct |
21 |
Correct |
387 ms |
35632 KB |
Output is correct |
22 |
Correct |
874 ms |
35720 KB |
Output is correct |
23 |
Correct |
630 ms |
35744 KB |
Output is correct |
24 |
Correct |
661 ms |
35764 KB |
Output is correct |
25 |
Correct |
684 ms |
40872 KB |
Output is correct |
26 |
Correct |
777 ms |
40924 KB |
Output is correct |
27 |
Correct |
817 ms |
40916 KB |
Output is correct |
28 |
Correct |
507 ms |
40896 KB |
Output is correct |
29 |
Correct |
812 ms |
47192 KB |
Output is correct |
30 |
Correct |
753 ms |
47184 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
35520 KB |
Output is correct |
2 |
Execution timed out |
3074 ms |
35428 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
35520 KB |
Output is correct |
2 |
Execution timed out |
3074 ms |
35428 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |