This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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;
return z;
}
void build(int l, int r, int k){
lazy[k] = 0;
if(l == r){
T[k] = {
val[l],
1-val[l],
1-val[l],
val[l]
};
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(){
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 (stderr)
circuit.cpp: In function 'void build(int, int, int)':
circuit.cpp:40:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
40 | int m = l+r>>1;
| ~^~
circuit.cpp: In function 'void upd(int, int, int, int, int)':
circuit.cpp:68:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
68 | int m = l+r>>1;
| ~^~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |