#include "circuit.h"
#include <bits/stdc++.h>
#define pb push_back
#define pf push_front
using namespace std;
#define F first
#define S second
typedef long long ll;
#define pii pair <int, int>
#define pll pair <ll, ll>
typedef long double ld;
const ll N = 2 * 1e5 + 100, M = 4096 + 10, len = 21, inf = 1e18;
const ll mod = 1000002022;
ll um(ll a, ll b){
return (1LL * a * b) % mod;
}
ll subr(ll a, ll b){
return ((1LL * a - b) % mod + mod) % mod;
}
vector <int> q[N];
int in[N], n, m, sz;
struct seg{
vector <pll> tree;
vector <bool> have;
void init(){
sz = 1;
while(sz < n) sz *= 2;
tree.assign(2 * sz - 1, {0LL, 0LL});
have.assign(2 * sz - 1, false);
}
pll gt(pll a, pll b){
if(a.F == 0 && a.S == 0) return b;
if(b.F == 0 && b.S == 0) return a;
pll k;
k.F = a.F * b.F * 2 + a.F * b.S + a.S * b.F;
k.S = a.S * b.S * 2 + a.F * b.S + a.S * b.F;
return k;
}
void upd(ll i, pll v, ll x = 0, ll lx = 0, ll rx = sz){
while(rx - lx == 1){
tree[x] = v;
return;
}
ll mid = (rx + lx) / 2;
if(i < mid) upd(i, v, 2 * x + 1, lx, mid);
else upd(i, v, 2 * x + 2, mid, rx);
tree[x] = gt(tree[2 * x + 1], tree[2 * x + 2]);
}
void push(ll x, ll lx, ll rx){
if(rx - lx == 1) return;
have[2 * x + 1] = (have[2 * x + 1] ^ have[x]);
have[2 * x + 2] = (have[2 * x + 2] ^ have[x]);
have[x] = 0;
}
pll get(ll l, ll r, ll x = 0, ll lx = 0, ll rx = sz){
if(l >= rx || lx >= r) return {0LL, 0LL};
if(l <= lx && rx <= r){
have[x] = (have[x] ^ 1);
if(have[x]) return {tree[x].S, tree[x].F};
return tree[x];
}
push(x, lx, rx);
ll mid = (lx + rx) / 2;
pll s1 = get(l, r, 2 * x + 1, lx, mid);
pll s2 = get(l, r, 2 * x + 2, mid, rx);
return gt(s1, s2);
}
} obj;
void init(int nx, int mx, vector<int> p, vector<int> a) {
n = nx;
m = mx;
obj.init();
for(int i = 1; i < n + m; i++){
q[p[i]].pb(i);
}
for(int i = n; i < n + m; i++){
in[i] = a[i - n];
if(in[i]) obj.upd(i - n, {1, 0});
else obj.upd(i - n, {0, 1});
}
}
int count_ways(int l, int r) {
pll rs = obj.get(l, r);
return (int)rs.F;
}
# | 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... |