#include "circuit.h"
#include <bits/stdc++.h>
using namespace std;
constexpr int MAXN = 100000;
constexpr int MOD = 1e9+2022;
struct SegTree{
int tag[MAXN];
array<int,2> ans[MAXN], rev[MAXN];
int sz;
void upd(int node){
ans[node][0]=(1ll*ans[node*2+1][0]*ans[node*2+2][0]*2)%MOD;
ans[node][0]+=(1ll*ans[node*2+1][0]*ans[node*2+2][1])%MOD;
if (ans[node][0]>=MOD) ans[node][0]-=MOD;
ans[node][0]+=(1ll*ans[node*2+1][1]*ans[node*2+2][0])%MOD;
if (ans[node][0]>=MOD) ans[node][0]-=MOD;
ans[node][1]+=(1ll*ans[node*2+1][1]*ans[node*2+2][0])%MOD;
if (ans[node][1]>=MOD) ans[node][1]-=MOD;
ans[node][1]+=(1ll*ans[node*2+1][0]*ans[node*2+2][1])%MOD;
if (ans[node][1]>=MOD) ans[node][1]-=MOD;
ans[node][1]+=(1ll*ans[node*2+1][1]*ans[node*2+2][1]*2)%MOD;
if (ans[node][1]>=MOD) ans[node][1]-=MOD;
rev[node][0]=(1ll*rev[node*2+1][0]*rev[node*2+2][0]*2)%MOD;
if (rev[node][0]>=MOD) rev[node][0]-=MOD;
rev[node][0]+=(1ll*rev[node*2+1][0]*rev[node*2+2][1])%MOD;
if (rev[node][0]>=MOD) rev[node][0]-=MOD;
rev[node][0]+=(1ll*rev[node*2+1][1]*rev[node*2+2][0])%MOD;
if (rev[node][0]>=MOD) rev[node][0]-=MOD;
rev[node][1]+=(1ll*rev[node*2+1][1]*rev[node*2+2][0])%MOD;
if (rev[node][1]>=MOD) rev[node][1]-=MOD;
rev[node][1]+=(1ll*rev[node*2+1][0]*rev[node*2+2][1])%MOD;
if (rev[node][1]>=MOD) rev[node][1]-=MOD;
rev[node][1]+=(1ll*rev[node*2+1][1]*rev[node*2+2][1]*2)%MOD;
if (rev[node][1]>=MOD) rev[node][1]-=MOD;
}
void dallan(int node){
if (tag[node]){
swap(ans[node],rev[node]);
if (node*2+1<sz){
tag[node*2+1]^=1;
tag[node*2+2]^=1;
}
tag[node]=0;
}
}
SegTree(vector<int> arr):sz(arr.size()*2-1){
fill(tag,tag+sz,0);
for (int i = 0; i < arr.size(); i++){
ans[i+sz/2][arr[i]]=1;
ans[i+sz/2][arr[i]^1]=0;
rev[i+sz/2]=ans[i+sz/2];
swap(rev[i+sz/2][0],rev[i+sz/2][1]);
}
for (int i = sz/2-1; i >= 0; i--){
upd(i);
}
}
void update(int tl, int tr, int l = 0, int r = -1, int node = 0){
if (r==-1) r = sz/2;
dallan(node);
if (tl>=l && tr<=r){
return tag[node]=1,dallan(node);
}
if (l>tr || r<tl) return;
int mid = l+(r-l)/2;
if (tl<=mid) update(tl,tr,l,mid,node*2+1);
if (mid<tr) update(tl,tr,mid+1,r,node*2+2);
upd(node);
}
} *segtree=nullptr;
int n;
void init(int N, int M, std::vector<int> P, std::vector<int> A) {
n=N;
segtree=new SegTree(A);
}
int count_ways(int L, int R) {
L-=n,R-=n;
segtree->update(L,R);
return (segtree->ans)[0][1];
}
Compilation message
circuit.cpp: In constructor 'SegTree::SegTree(std::vector<int>)':
circuit.cpp:49:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
49 | for (int i = 0; i < arr.size(); i++){
| ~~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
1st lines differ - on the 1st token, expected: '1', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
1st lines differ - on the 1st token, expected: '1', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
1st lines differ - on the 1st token, expected: '1', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
298 ms |
2624 KB |
1st lines differ - on the 1st token, expected: '431985922', found: '122991304' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
298 ms |
2624 KB |
1st lines differ - on the 1st token, expected: '431985922', found: '122991304' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
1st lines differ - on the 1st token, expected: '1', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
1st lines differ - on the 1st token, expected: '1', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
1st lines differ - on the 1st token, expected: '1', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |