This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define int long long
#ifdef LOCAL
#include "algo/debug.h"
#else
#define debug(...) 42
#endif
#define all(a) (a).begin(), (a).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define reps(i, s, n) for (int i = s; i < (n); ++i)
#define pb push_back
#define sz(a) (int) (a.size())
const int mod = 1e9 + 7;
int power(int a, int n) {
int res = 1;
while (n) {
if (n % 2) {
(res *= a) %= mod;
}
(a *= a) %= mod;
n /= 2;
}
return res;
}
// typedef vector<vector<int>> matrix;
// matrix mul(matrix a, matrix b) {
// matrix res(sz(a), vector<int> (sz(b[0])));
// rep(i, sz(a)) {
// rep(j, sz(b[0])) {
// rep(k, sz(a[0])) {
// (res[i][j] += a[i][k] * b[k][j]) %= mod;
// }
// }
// }
// return res;
// }
// matrix matpow(matrix a, int s, int n) {
// matrix res(s, vector<int> (s));
// rep(i, s) {
// res[i][i] = 1;
// }
// while (n) {
// if (n & 1) {
// res = mul(res, a);
// }
// a = mul(a, a);
// n /= 2;
// }
// return res;
// }
void solve() {
int n, m, k;
cin >> n >> m >> k;
vector<int> x(k), y(k), t(k);
rep(i, k) {
char c;
cin >> c >> x[i] >> y[i];
t[i] = (c == '+');
--x[i], --y[i];
}
// debug(x);
// debug(y);
if (k == 0){
cout << (power(2, n) + power(2, m) - 2 + 5 * mod) % mod;
return;
}
// matrix transition{{1, 1}, {1, 0}};
if (n == 1 || m == 1) {
cout << power(2, n * m - k);
return;
}
bool need = 0;
int res = 0;
auto add = [&] () -> void {
map<int, int> mp;
rep(i, k) {
// debug(i, y[i]);
int type = (t[i] == 1 ? (x[i] & 1) : (x[i] & 1 ^ 1));
if (mp.find(y[i]) != mp.end() && mp[y[i]] != type) {
return;
}
mp[y[i]] = type;
}
// debug(mp);
// debug(sz(mp));
(res += power(2, m - sz(mp))) %= mod;
bool del = 1;
int prv = -1, prv_type = -1;
for (auto &[y, type] : mp) {
if (prv != -1) {
del &= (y - prv) % 2 == ((type == prv_type) ^ 1);
}
prv = y;
prv_type = type;
}
need |= del;
};
add();
// debug(res);
rep(i, k) {
int xx = x[i];
int yy = y[i];
y[i] = n - 1 - xx;
x[i] = yy;
}
swap(n, m);
add();
// debug(res);
if (need) {
res -= 1;
if (res < 0) {
res += mod;
}
}
cout << res;
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
solve();
return 0;
}
Compilation message (stderr)
plusminus.cpp: In lambda function:
plusminus.cpp:93:50: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
93 | int type = (t[i] == 1 ? (x[i] & 1) : (x[i] & 1 ^ 1));
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |