#include "circuit.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int nx=2e5+5, mod=1e9+2022;
int n, m, p[nx], sz[nx], v[nx];
vector<int> d[nx];
void dfs(int u)
{
for (auto v:d[u]) sz[v]=sz[u]+1, dfs(v);
}
struct segtree
{
int d1[2*nx], d2[2*nx];
bool lz[2*nx];
void build(int l, int r, int i, vector<int> &t)
{
if (l==r) return t[l]?d1[i]=v[l]:d2[i]=v[l], void();
int md=(l+r)/2;
build(l, md, 2*i, t);
build(md+1, r, 2*i+1, t);
d1[i]=(d1[2*i]+d1[2*i+1])%mod;
d2[i]=(d2[2*i]+d2[2*i+1])%mod;
}
void pushlz(int l, int r, int i)
{
if (!lz[i]) return;
lz[i]=0; swap(d1[i], d2[i]);
if (l==r) return;
lz[2*i]=!lz[2*i];
lz[2*i+1]=!lz[2*i+1];
}
void update(int l, int r, int i, int ql, int qr)
{
pushlz(l, r, i);
if (r<ql||qr<l) return;
if (ql<=l&&r<=qr) return lz[i]=1, pushlz(l, r, i), void();
int md=(l+r)/2;
update(l, md, 2*i, ql, qr);
update(md+1, r, 2*i+1, ql, qr);
d1[i]=(d1[2*i]+d1[2*i+1])%mod;
d2[i]=(d2[2*i]+d2[2*i+1])%mod;
}
} s;
void init(int N, int M, std::vector<int> P, std::vector<int> A) {
p[0]=1; n=N; m=M;
for (int i=1; i<N+M; i++) p[i]=(p[i-1]*2)%mod;
for (int i=1; i<N+M; i++) d[P[i]].push_back(i);
dfs(0);
for (int i=N; i<N+M; i++) v[i-N]=p[N-sz[i]];
s.build(0, M-1, 1, A);
}
int count_ways(int L, int R) {;
s.update(0, m-1, 1, L-n, R-n);
return s.d1[1];
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
10584 KB |
Output is correct |
2 |
Correct |
2 ms |
10688 KB |
Output is correct |
3 |
Correct |
2 ms |
10584 KB |
Output is correct |
4 |
Correct |
2 ms |
10584 KB |
Output is correct |
5 |
Correct |
1 ms |
8536 KB |
Output is correct |
6 |
Correct |
2 ms |
8536 KB |
Output is correct |
7 |
Correct |
2 ms |
8536 KB |
Output is correct |
8 |
Correct |
2 ms |
10584 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
10584 KB |
Output is correct |
2 |
Correct |
1 ms |
10584 KB |
Output is correct |
3 |
Correct |
3 ms |
10584 KB |
Output is correct |
4 |
Correct |
2 ms |
10584 KB |
Output is correct |
5 |
Correct |
2 ms |
10584 KB |
Output is correct |
6 |
Correct |
2 ms |
8536 KB |
Output is correct |
7 |
Correct |
2 ms |
10584 KB |
Output is correct |
8 |
Correct |
2 ms |
10584 KB |
Output is correct |
9 |
Correct |
2 ms |
10584 KB |
Output is correct |
10 |
Correct |
2 ms |
10584 KB |
Output is correct |
11 |
Correct |
2 ms |
10700 KB |
Output is correct |
12 |
Correct |
2 ms |
8536 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
10584 KB |
Output is correct |
2 |
Correct |
2 ms |
10688 KB |
Output is correct |
3 |
Correct |
2 ms |
10584 KB |
Output is correct |
4 |
Correct |
2 ms |
10584 KB |
Output is correct |
5 |
Correct |
1 ms |
8536 KB |
Output is correct |
6 |
Correct |
2 ms |
8536 KB |
Output is correct |
7 |
Correct |
2 ms |
8536 KB |
Output is correct |
8 |
Correct |
2 ms |
10584 KB |
Output is correct |
9 |
Correct |
2 ms |
10584 KB |
Output is correct |
10 |
Correct |
1 ms |
10584 KB |
Output is correct |
11 |
Correct |
3 ms |
10584 KB |
Output is correct |
12 |
Correct |
2 ms |
10584 KB |
Output is correct |
13 |
Correct |
2 ms |
10584 KB |
Output is correct |
14 |
Correct |
2 ms |
8536 KB |
Output is correct |
15 |
Correct |
2 ms |
10584 KB |
Output is correct |
16 |
Correct |
2 ms |
10584 KB |
Output is correct |
17 |
Correct |
2 ms |
10584 KB |
Output is correct |
18 |
Correct |
2 ms |
10584 KB |
Output is correct |
19 |
Correct |
2 ms |
10700 KB |
Output is correct |
20 |
Correct |
2 ms |
8536 KB |
Output is correct |
21 |
Incorrect |
2 ms |
10584 KB |
1st lines differ - on the 1st token, expected: '759476520', found: '833967706' |
22 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
408 ms |
12788 KB |
Output is correct |
2 |
Correct |
619 ms |
14288 KB |
Output is correct |
3 |
Correct |
563 ms |
14284 KB |
Output is correct |
4 |
Correct |
598 ms |
14292 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
408 ms |
12788 KB |
Output is correct |
2 |
Correct |
619 ms |
14288 KB |
Output is correct |
3 |
Correct |
563 ms |
14284 KB |
Output is correct |
4 |
Correct |
598 ms |
14292 KB |
Output is correct |
5 |
Correct |
441 ms |
12632 KB |
Output is correct |
6 |
Correct |
567 ms |
14292 KB |
Output is correct |
7 |
Correct |
584 ms |
14292 KB |
Output is correct |
8 |
Correct |
547 ms |
14288 KB |
Output is correct |
9 |
Correct |
254 ms |
8792 KB |
Output is correct |
10 |
Correct |
498 ms |
10840 KB |
Output is correct |
11 |
Correct |
560 ms |
10840 KB |
Output is correct |
12 |
Correct |
594 ms |
8792 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
10584 KB |
Output is correct |
2 |
Correct |
1 ms |
10584 KB |
Output is correct |
3 |
Correct |
3 ms |
10584 KB |
Output is correct |
4 |
Correct |
2 ms |
10584 KB |
Output is correct |
5 |
Correct |
2 ms |
10584 KB |
Output is correct |
6 |
Correct |
2 ms |
8536 KB |
Output is correct |
7 |
Correct |
2 ms |
10584 KB |
Output is correct |
8 |
Correct |
2 ms |
10584 KB |
Output is correct |
9 |
Correct |
2 ms |
10584 KB |
Output is correct |
10 |
Correct |
2 ms |
10584 KB |
Output is correct |
11 |
Correct |
2 ms |
10700 KB |
Output is correct |
12 |
Correct |
2 ms |
8536 KB |
Output is correct |
13 |
Correct |
408 ms |
12788 KB |
Output is correct |
14 |
Correct |
619 ms |
14288 KB |
Output is correct |
15 |
Correct |
563 ms |
14284 KB |
Output is correct |
16 |
Correct |
598 ms |
14292 KB |
Output is correct |
17 |
Correct |
441 ms |
12632 KB |
Output is correct |
18 |
Correct |
567 ms |
14292 KB |
Output is correct |
19 |
Correct |
584 ms |
14292 KB |
Output is correct |
20 |
Correct |
547 ms |
14288 KB |
Output is correct |
21 |
Correct |
254 ms |
8792 KB |
Output is correct |
22 |
Correct |
498 ms |
10840 KB |
Output is correct |
23 |
Correct |
560 ms |
10840 KB |
Output is correct |
24 |
Correct |
594 ms |
8792 KB |
Output is correct |
25 |
Correct |
656 ms |
16612 KB |
Output is correct |
26 |
Correct |
660 ms |
16476 KB |
Output is correct |
27 |
Correct |
635 ms |
16476 KB |
Output is correct |
28 |
Correct |
503 ms |
16460 KB |
Output is correct |
29 |
Correct |
616 ms |
19020 KB |
Output is correct |
30 |
Correct |
620 ms |
19044 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
10584 KB |
Output is correct |
2 |
Correct |
2 ms |
10688 KB |
Output is correct |
3 |
Correct |
2 ms |
10584 KB |
Output is correct |
4 |
Correct |
2 ms |
10584 KB |
Output is correct |
5 |
Correct |
1 ms |
8536 KB |
Output is correct |
6 |
Correct |
2 ms |
8536 KB |
Output is correct |
7 |
Correct |
2 ms |
8536 KB |
Output is correct |
8 |
Correct |
2 ms |
10584 KB |
Output is correct |
9 |
Correct |
2 ms |
10584 KB |
Output is correct |
10 |
Correct |
1 ms |
10584 KB |
Output is correct |
11 |
Correct |
3 ms |
10584 KB |
Output is correct |
12 |
Correct |
2 ms |
10584 KB |
Output is correct |
13 |
Correct |
2 ms |
10584 KB |
Output is correct |
14 |
Correct |
2 ms |
8536 KB |
Output is correct |
15 |
Correct |
2 ms |
10584 KB |
Output is correct |
16 |
Correct |
2 ms |
10584 KB |
Output is correct |
17 |
Correct |
2 ms |
10584 KB |
Output is correct |
18 |
Correct |
2 ms |
10584 KB |
Output is correct |
19 |
Correct |
2 ms |
10700 KB |
Output is correct |
20 |
Correct |
2 ms |
8536 KB |
Output is correct |
21 |
Incorrect |
2 ms |
10584 KB |
1st lines differ - on the 1st token, expected: '759476520', found: '833967706' |
22 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
10584 KB |
Output is correct |
2 |
Correct |
2 ms |
10688 KB |
Output is correct |
3 |
Correct |
2 ms |
10584 KB |
Output is correct |
4 |
Correct |
2 ms |
10584 KB |
Output is correct |
5 |
Correct |
1 ms |
8536 KB |
Output is correct |
6 |
Correct |
2 ms |
8536 KB |
Output is correct |
7 |
Correct |
2 ms |
8536 KB |
Output is correct |
8 |
Correct |
2 ms |
10584 KB |
Output is correct |
9 |
Correct |
2 ms |
10584 KB |
Output is correct |
10 |
Correct |
1 ms |
10584 KB |
Output is correct |
11 |
Correct |
3 ms |
10584 KB |
Output is correct |
12 |
Correct |
2 ms |
10584 KB |
Output is correct |
13 |
Correct |
2 ms |
10584 KB |
Output is correct |
14 |
Correct |
2 ms |
8536 KB |
Output is correct |
15 |
Correct |
2 ms |
10584 KB |
Output is correct |
16 |
Correct |
2 ms |
10584 KB |
Output is correct |
17 |
Correct |
2 ms |
10584 KB |
Output is correct |
18 |
Correct |
2 ms |
10584 KB |
Output is correct |
19 |
Correct |
2 ms |
10700 KB |
Output is correct |
20 |
Correct |
2 ms |
8536 KB |
Output is correct |
21 |
Incorrect |
2 ms |
10584 KB |
1st lines differ - on the 1st token, expected: '759476520', found: '833967706' |
22 |
Halted |
0 ms |
0 KB |
- |