#include "circuit.h"
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define en cout << '\n'
#define all(x) x.begin(),x.end()
#define pii pair<int,int>
#define vi vector<int>
#define ll long long int
#define ff first
#define ss second
#define MOD 1000002022
const int N = 500000+10;
int n, m;
vector<int> g[N];
array<ll, 4> T[N];
vi val;
int lazy[N];
int F;
array<ll, 4> comb(array<ll, 4> x, array<ll, 4> y){
array<ll, 4> z;
z[0] = x[0] * y[0] % MOD;
z[1] = (x[0] * y[1] + x[1] * y[0] + x[1] * y[1]) % MOD;
z[2] = x[2] * y[2] % MOD;
z[3] = (x[2] * y[3] + x[3] * y[2] + x[3] * y[3]) % MOD;
// cout << z[3] << ' ';
return z;
}
void build(int l, int r, int k){
lazy[k] = 0;
if(l == r){
T[k] = {
1-val[l],
val[l],
val[l],
1-val[l]
};
// cout << val[l] << 'f';
return;
}
int m = l+r>>1;
build(l, m, k<<1);
build(m+1, r, k<<1|1);
T[k] = comb(T[k<<1], T[k<<1|1]);
}
int get(){
// cout << T[1][0] << ' ' << T[1][1] << ' ' << T[1][2] << ' ' << T[1][3] << '\n';
return T[1][1];
}
void push(int k){
if(lazy[k]){
lazy[k<<1] ^= lazy[k];
lazy[k<<1|1] ^= lazy[k];
swap(T[k<<1][0], T[k<<1][2]);
swap(T[k<<1][1], T[k<<1][3]);
swap(T[k<<1|1][0], T[k<<1|1][2]);
swap(T[k<<1|1][1], T[k<<1|1][3]);
lazy[k] = 0;
}
}
void upd(int l, int r, int ql, int qr, int k){
if(ql > r || l > qr) return;
if(ql <= l && r <= qr){
swap(T[k][0], T[k][2]);
swap(T[k][1], T[k][3]);
lazy[k] ^= 1;
return;
}
push(k);
int m = l+r>>1;
upd(l, m, ql, qr, k<<1);
upd(m+1, r, ql, qr, k<<1|1);
T[k] = comb(T[k<<1], T[k<<1|1]);
}
void init(int nn, int mm, std::vector<int> P, std::vector<int> A) { n=nn, m=mm;
for(int i = 1; i < n + m; ++i) g[P[i]].pb(i);
val = A;
build(0, m - 1, 1);
}
int count_ways(int L, int R) {
L -= n, R -= n;
upd(0, m - 1, L, R, 1);
return get();
}
Compilation message
circuit.cpp: In function 'void build(int, int, int)':
circuit.cpp:42:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
42 | int m = l+r>>1;
| ~^~
circuit.cpp: In function 'void upd(int, int, int, int, int)':
circuit.cpp:71:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
71 | int m = l+r>>1;
| ~^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
15192 KB |
2nd lines differ - on the 1st token, expected: '2', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
15192 KB |
2nd lines differ - on the 1st token, expected: '2', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
15192 KB |
2nd lines differ - on the 1st token, expected: '2', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
301 ms |
19236 KB |
1st lines differ - on the 1st token, expected: '431985922', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
301 ms |
19236 KB |
1st lines differ - on the 1st token, expected: '431985922', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
15192 KB |
2nd lines differ - on the 1st token, expected: '2', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
15192 KB |
2nd lines differ - on the 1st token, expected: '2', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
15192 KB |
2nd lines differ - on the 1st token, expected: '2', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |