rt,线段树中 a 存的是必填 0 的位置,b 存的是必填 1 的位置,c 存的是 ? 的位置。
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 2e5 + 10;
int n, m, q, a[N], b[N], c[N];
struct Node
{
int a, b, c;
} tr[N << 2];
#define lson (rt << 1)
#define rson (rt << 1 | 1)
#define mid (l + r) / 2
void push_up(Node &a, Node b, Node c)
{
a.a = b.a | c.a;
a.b = b.b | c.b;
a.c = b.c & c.c;
}
void build(int rt, int l, int r)
{
if (l == r) return tr[rt] = {a[l], b[l], c[l]}, void();
build(lson, l, mid);
build(rson, mid + 1, r);
push_up(tr[rt], tr[lson], tr[rson]);
}
void update(int rt, int l, int r, int p, int a, int b, int c)
{
if (l == r) return tr[rt] = {a, b, c}, void();
if (p <= mid) update(lson, l, mid, p, a, b, c);
else update(rson, mid + 1, r, p, a, b, c);
push_up(tr[rt], tr[lson], tr[rson]);
}
Node query(int rt, int l, int r, int sp, int ep)
{
if (sp <= l && r <= ep) return tr[rt];
Node res;
bool f = 0;
if (sp <= mid) res = query(lson, l, mid, sp, ep), f = 1;
if (ep > mid)
{
if (f) push_up(res, res, query(rson, mid + 1, r, sp, ep));
else res = query(rson, mid + 1, r, sp, ep);
}
return res;
}
#define lb(o) (o & (-o))
int get(int x)
{
int cnt = 0;
while (x) cnt++, x -= lb(x);
return cnt;
}
int fpm(int a, int n)
{
int res = 1;
while (n)
{
if (n & 1) res *= a;
a *= a;
n /= 2;
}
return res;
}
signed main()
{
cin.tie(0)->ios::sync_with_stdio(false);
cin >> n >> m >> q;
for (int i = 1; i <= m; i++)
{
string s;
cin >> s;
int x = 0, y = 0, z = 0;
for (int j = 0; j < s.size(); j++)
{
if (s[j] == '0') x += (1 << j);
if (s[j] == '1') y += (1 << j);
if (s[j] == '?') z += (1 << j);
}
a[i] = x;
b[i] = y;
c[i] = z;
}
build(1, 1, m);
int res = 0;
while (q--)
{
int op;
cin >> op;
if (op == 0)
{
int l, r;
cin >> l >> r;
auto x = query(1, 1, m, l, r);
if (x.a & x.b != 0) res ^= 0;
else res ^= fpm(2, get(x.c));
}
else
{
int p;
string s;
cin >> p >> s;
int x = 0, y = 0, z = 0;
for (int i = 0; i < s.size(); i++)
{
if (s[i] == '0') x += (1 << i);
if (s[i] == '1') y += (1 << i);
if (s[i] == '?') z += (1 << i);
}
update(1, 1, m, p, x, y, z);
}
}
cout << res;
return 0;
}