#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll base = 1e9 + 7;
const int N = 1e6 + 10;
ll row[N], col[N];
void mul(ll &x, ll y) { (x *= y) %= base; }
void sum(ll &x, ll y) { (x += y) %= base; }
int main() {
ll n, m, q;
cin >> n >> m >> q;
for (int i = 1; i <= n; ++i)
row[i] = 1;
for (int j = 1; j <= m; ++j)
col[j] = 1;
while (q--) {
char type; ll x, y;
cin >> type >> x >> y;
if (type == 'R') mul(row[x], y);
else mul(col[x], y);
}
ll sm = 0;
for (int i = 1; i <= m; ++i)
sum(sm, col[i]);
ll cr = 0;
for (int i = 1; i <= m; ++i) {
ll vl = col[i];
mul(vl, i);
sum(cr, vl);
}
ll ans = 0;
for (int i = 1; i <= n; ++i) {
ll vl = cr;
mul(vl, row[i]);
sum(ans, vl);
vl = sm;
mul(vl, m);
sum(cr, vl);
}
cout << ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
6 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
9 ms |
2816 KB |
Output is correct |
12 |
Correct |
17 ms |
8704 KB |
Output is correct |
13 |
Correct |
6 ms |
896 KB |
Output is correct |
14 |
Correct |
18 ms |
10112 KB |
Output is correct |
15 |
Correct |
18 ms |
9088 KB |
Output is correct |
16 |
Correct |
28 ms |
16000 KB |
Output is correct |
17 |
Correct |
28 ms |
16000 KB |
Output is correct |
18 |
Correct |
28 ms |
16000 KB |
Output is correct |
19 |
Correct |
28 ms |
16000 KB |
Output is correct |
20 |
Correct |
29 ms |
16000 KB |
Output is correct |