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
const int N = 500000+10;
const ll MOD = 1000002022;
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] + x[0] * y[0] + x[0] * y[1] + x[1] * y[0]) % MOD;
// z[1] = (x[0] * y[1] + x[1] * y[0] + x[1] * y[1] + x[1] * y[1]) % MOD;
// z[2] = (x[2] * y[2] + x[2] * y[2] + x[2] * y[3] + x[3] * y[2]) % MOD;
// z[3] = (x[2] * y[3] + x[3] * y[2] + x[3] * y[3] + x[3] * y[3]) % MOD;
// cout << z[3] << ' ';
z[1] = x[1] + y[1];
z[3] = x[3] + y[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 dfs(int v){
// if(g[v].size() == 0){
// // dp[v][0] = 1-val[v - n];
// dp[v][1] = val[v - n];
// return;
// }
// int s = g[v].size();
// for(int i =0 ; i <= s; ++i) dp[v][i] = 0;
// for(int u: g[v]){
// dfs(u);
// for(int j = s; j > 0; --j){
// dp[v][j] = dp[v][j] * pd[u][0];
// dp[v][j] = dp[v][j - 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);
// for(int i = L; i <= R; ++i) val[i] ^= 1;
// dfs(0);
int num = get();
return num;
}
Compilation message (stderr)
circuit.cpp: In function 'void build(int, int, int)':
circuit.cpp:43:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
43 | int m = l+r>>1;
| ~^~
circuit.cpp: In function 'void upd(int, int, int, int, int)':
circuit.cpp:72:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
72 | 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... |