55分树状数组求助!悬赏关注!(急)
查看原帖
55分树状数组求助!悬赏关注!(急)
494699
卷王慢即快楼主2022/12/27 15:19

记录

#include <bits/stdc++.h>
using namespace std;
int n, m, q, ans = 0;
int a[100010][50], c[5][100001][50];
string s;
inline int sum(int x, int bit, int opt)
{
	int res = 0;
	for(int i = x; i; i -= i & (-i)) res += c[opt][i][bit];
	return res;
}
inline void add(int x, int bit, int y, int opt)
{
	for(int i = x; i <= m; i += i & (-i)) c[opt][i][bit] += y;
}
inline int work(int l, int r)
{
	int cnt = 1;
	for(int i = 1; i <= n; i++)
	{
		if(sum(r, i, 0) - sum(l - 1, i, 0) > 0 &&
		   sum(r, i, 1) - sum(l - 1, i, 1) > 0 ) return 0;
		if(sum(r, i, 2) - sum(l - 1, i, 2) == r - l + 1) cnt = cnt * 2;
	}
	return cnt;
}
inline void cr(int x)
{
	for(int i = 1; i <= n; i++)
	{
		add(x, i, -1, a[x][i]);
		if(s[i - 1] == '?') a[x][i] = 2;
		else a[x][i] = s[i - 1] - '0';
		add(x, i, 1, a[x][i]);
	}
}
int main()
{
	speed: std::ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	cin >> n >> m >> q;
	bool flag = 0;
	for(int i = 1; i <= m; i++)
	{
		cin >> s;
		for(int j = 1; j <= n; j++)
		{
			if(s[j - 1] == '?') a[i][j] = 2;
			else a[i][j] = s[j - 1] - '0';
			add(i, j, 1, a[i][j]);
		}
	}
	while(q--)
	{
		int opt, l, r, pos;
		cin >> opt;
		if(opt == 0)
		{
			cin >> l >> r;
			ans ^= work(l, r);
		}
		else
		{
			cin >> pos >> s;
			cr(pos);
		}
	}
	cout << ans;
	return 0;
}
2022/12/27 15:19
加载中...