# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
891246 | Tien_Noob | Automobil (COCI17_automobil) | C++17 | 13 ms | 8536 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//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 (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |