Submission #104274

#TimeUsernameProblemLanguageResultExecution timeMemory
104274KewoAutomobil (COCI17_automobil)C++17
100 / 100
37 ms16248 KiB
#include <bits/stdc++.h>
#define pb push_back
#define ppb pop_back
#define fi first
#define se second
#define mid ((x + y) / 2)
#define left (ind * 2)
#define right (ind * 2 + 1)
#define mp make_pair
#define timer ((double)clock() / CLOCKS_PER_SEC)
#define endl "\n"
#define spc " "
#define d1(x) cerr<<#x<<":"<<x<<endl
#define d2(x, y) cerr<<#x<<":"<<x<<" "<<#y<<":"<<y<<endl
#define d3(x, y, z) cerr<<#x<<":"<<x<<" "<<#y<<":"<<y<<" "<<#z<<":"<<z<<endl
#define fast_io() ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;

typedef long long int lli;
typedef pair<lli, lli> ii;
typedef pair<ii, int> iii;
typedef pair<double, double> dd;

const int N = (int)(1e6 + 5);
const int LOG = (int)(20);
const lli mod = (lli)(1e9 + 7);

lli n, m, k, rr[N], cc[N], ans;
vector<lli> r, c;

lli get(lli x, lli y) {
	return (m * (x - 1) % mod + y) % mod;
}

lli sumr(lli x) {
	return ((m * m % mod) * (x - 1) % mod + (m * (m + 1) / 2) % mod) % mod;
}

lli sumc(lli x) {
	return (x * n % mod + m * ((n * (n - 1) / 2) % mod) % mod) % mod;
}

signed main() {
	fast_io();
	// freopen("inp.in", "r", stdin);

	memset(rr, -1, sizeof rr);
	memset(cc, -1, sizeof cc);

	cin >> n >> m >> k;

	for(lli i = 1; i <= k; i++) {
		char c;
		lli a, b;
		cin >> c >> a >> b;
		if(c == 'R') {
			if(rr[a] != -1) {
				rr[a] *= b;
				rr[a] %= mod;
			}
			else
				rr[a] = b;
		}
		else {
			if(cc[a] != -1) {
				cc[a] *= b;
				cc[a] %= mod;
			}
			else
				cc[a] = b;
		}
	}
	for(lli i = 1; i <= 1e6; i++) {
		if(rr[i] != -1)
			r.pb(i);
		if(cc[i] != -1)
			c.pb(i);
	}

	for(int i = 1; i <= n; i++) {
		ans += sumr(i);
		ans %= mod;	
	}

	for(auto i : r) {
		ans += sumr(i) * (rr[i] - 1) % mod;
		ans %= mod;
	}

	for(auto i : c) {
		ans += sumc(i) * (cc[i] - 1) % mod;
		ans %= mod;
	}

	for(auto i : r) {
		for(auto j : c) {
			ans += get(i, j) * ((rr[i] * cc[j] % mod + (mod - rr[i] - cc[j]) % mod)) % mod;
			ans %= mod;
			ans += get(i, j);
			ans %= mod;
		}
	}
	ans += mod;
	ans %= mod;
	cout << ans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...