记录编号 594856 评测结果 AAAAAAAAAAAAAAAAAAAA
题目名称 正负游戏 最终得分 100
用户昵称 Gravatar┭┮﹏┭┮ 是否通过 通过
代码语言 C++ 运行时间 0.572 s
提交时间 2024-10-05 20:44:22 内存使用 26.42 MiB
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define fi first
#define in inline
#define se second
#define mp make_pair
#define pb push_back
const int N = 1e6+10;
const ll mod = 998244353;

ll read(){
	ll x = 0,f = 1;char c = getchar();
	for(;c < '0' || c > '9';c = getchar())if(c == '-')f = -1;
	for(;c >= '0' && c <= '9';c = getchar())x = (x<<1) + (x<<3) + c-'0';
	return x * f;
}



int n,m,q;

ll ksm(ll x,ll y){
	ll ans = 1;
	while(y){
		if(y & 1)ans = ans * x % mod;
		x = x * x % mod,y >>= 1; 
	}return ans;
}

vector<int>s[N];
int main(){
	freopen("plusminus.in","r",stdin);
	freopen("plusminus.out","w",stdout);
	n = read(),m = read(),q = read();
	bool f = 0;
	if(n < m)swap(n,m),f = 1;
	for(int i = 1;i <= q;i++){
		int x = read(),y = read(),op = read();
		if(f)swap(x,y);
		s[x].pb(op);
	}
	if((n & 1) + (m & 1) == 1)return printf("0\n"),0;
	ll ans = 1;
	for(int i = 1;i <= n;i++){
		if(s[i].size() < m){
			ans = ans * ksm(2ll,(m - (int)s[i].size() - 1)) % mod;
		}
		else{
			int su = 1;
			for(int y : s[i])su *= y;
			if(su == 1)ans = 0;
		}
	}
	printf("%lld\n",ans * ksm(ksm(2ll,m - 1),mod - 2) % mod);

	return 0;

}