//Make CSP great again
//Vengeance
#include <bits/stdc++.h>
#define TASK "TESTCODE"
using namespace std;
const int mod = 1e9 + 7, N = 1e6;
int r[N + 1], c[N + 1], k;
long long n, m;
vector<int> updr, updc;
long long res;
void read()
{
cin >> n >> m >> k;
fill(r + 1, r + n + 1, 1);
fill(c + 1, c + m + 1, 1);
while(k--)
{
char t;
int x, y;
cin >> t >> x >> y;
if (t == 'R')
{
r[x] = (1LL * r[x] * y) % mod;
}
if (t == 'S')
{
c[x] = (1LL * c[x] * y) % mod;
}
}
}
void solve()
{
for (int i = 1; i <= n; ++ i)
{
if (r[i] != 1)
{
res -= ((((i * m + (i - 1) * m + 1) * m / 2) % mod)) % mod;
res %= mod;
updr.push_back(i);
}
res += (((i * m + (i - 1) * m + 1) * m / 2) % mod) % mod;
res %= mod;
}
for (int j = 1; j <= m; ++ j)
{
if (c[j] != 1)
{
updc.push_back(j);
res -= ((((n - 1) * m + j + j) * n / 2) % mod) % mod;
res %= mod;
}
}
for (int i : updr)
{
res += ((((i * m + (i - 1) * m + 1) * m / 2) % mod) * r[i]) % mod;
res %= mod;
}
for (int j : updc)
{
res += ((((n - 1) * m + j + j) * n / 2) % mod * c[j]) % mod;
}
for (int i : updr)
{
for (int j : updc)
{
long long cur = ((i - 1) * m + j) % mod;
res += cur;
res -= (cur * r[i]) % mod;
res -= (cur * c[j]) % mod;
res += ((cur * r[i]) % mod * c[j]) % mod;
res %= mod;
}
}
cout << (res + mod) % mod;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
if (fopen(TASK".INP", "r"))
{
freopen(TASK".INP", "r", stdin);
//freopen(TASK".OUT", "w", stdout);
}
int t = 1;
bool typetest = false;
if (typetest)
{
cin >> t;
}
for (int __ = 1; __ <= t; ++ __)
{
//cout << "Case " << __ << ": ";
read();
solve();
}
}
Compilation message
automobil.cpp: In function 'int main()':
automobil.cpp:82:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
82 | freopen(TASK".INP", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2392 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2392 KB |
Output is correct |
5 |
Correct |
1 ms |
2520 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2392 KB |
Output is correct |
8 |
Correct |
1 ms |
2768 KB |
Output is correct |
9 |
Correct |
1 ms |
2392 KB |
Output is correct |
10 |
Correct |
2 ms |
2396 KB |
Output is correct |
11 |
Correct |
3 ms |
6748 KB |
Output is correct |
12 |
Correct |
7 ms |
7004 KB |
Output is correct |
13 |
Correct |
2 ms |
4560 KB |
Output is correct |
14 |
Correct |
6 ms |
7648 KB |
Output is correct |
15 |
Correct |
7 ms |
6748 KB |
Output is correct |
16 |
Correct |
11 ms |
8284 KB |
Output is correct |
17 |
Correct |
12 ms |
8536 KB |
Output is correct |
18 |
Correct |
11 ms |
8284 KB |
Output is correct |
19 |
Correct |
11 ms |
8284 KB |
Output is correct |
20 |
Correct |
13 ms |
8304 KB |
Output is correct |