#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
#define pb push_back
#define F first
#define S second
#define all(x) (x).begin(),(x).end()
#define int long long
const int maxn = 1e6 + 10;
//const int maxs = 9;
const int inf = 1e9 + 10;
const int mod = 1e9 + 7;
ll pw(ll a, ll b) {
ll ret = 1;
while (b) {
if (b & 1) {
(ret *= a) %= mod;
}
b /= 2;
(a *= a) %= mod;
}
return ret;
}
map<int, int> clr, clc;
int n, m, k, x, y, d, cntr, cntc, tmp;
bool fc = 1, fr = 1;
signed main() {
cin >> n >> m >> k;
for (int i = 1; i <= k; i++) {
char s;
cin >> s >> x >> y;
int c = (s == '+');
int xr = ((x ^ y ^ c) & 1) + 1;
if (clr[x]) {
if (clr[x] != xr)
fr = 0;
}
else {
clr[x] = xr;
cntr++;
}
if (clc[y]) {
if (clc[y] != xr) {
fc = 0;
}
}
else {
clc[y] = xr;
cntc++;
}
// cntc++;
if (tmp) {
if (tmp != xr) {
d = 1;
}
}
else {
tmp = xr;
}
}
ll ans = 0;
if (fr)
(ans += pw(2, n - cntr)) % mod;
if (fc)
(ans += pw(2, m - cntc)) % mod;
ans = (ans - (!d) - (!k) + mod) % mod;
cout << ans << '\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |