제출 #1337527

#제출 시각아이디문제언어결과실행 시간메모리
1337527vache_kocharyanAutomobil (COCI17_automobil)C++20
100 / 100
14 ms16092 KiB
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const bool debug = true;

#define ff first
#define ss second
#define yes cout << "Yes\n"
#define no cout << "No\n"
#define YN(x) if(x)yes; else no;
#define all(X) (X).begin(), (X).end()
#define rall(X) (X).rbegin(), (X).rend()
#define blt __builtin_popcount

const int mod = 1e9 + 7;

#ifndef ONLINE_JUDGE
#define dbg(x) cerr << #x <<" "; print(x); cerr << endl;
#else
#define dbg(x)
#endif

#ifdef _MSC_VER
#include <intrin.h>
#define __builtin_popcount __popcnt
#define __builtin_popcountll __popcnt64
#endif

void print(long long t) { cerr << t; }
void print(int t) { cerr << t; }
void print(string t) { cerr << t; }
void print(char t) { cerr << t; }
void print(double t) { cerr << t; }
void print(long double t) { cerr << t; }
void print(unsigned long long t) { cerr << t; }

template <class T, class V> void print(pair <T, V> p);
template <class T> void print(vector <T> v);
template <class T> void print(set <T> v);
template <class T, class V> void print(map <T, V> v);
template <class T> void print(multiset <T> v);
template <class T, class V> void print(T v[], V n) { cerr << "["; for (int i = 0; i < n; i++) { cerr << v[i] << " "; } cerr << "]"; }
template <class T, class V> void print(pair <T, V> p) { cerr << "{"; print(p.first); cerr << ","; print(p.second); cerr << "}"; }
template <class T> void print(vector <T> v) { cerr << "[ "; for (T i : v) { print(i); cerr << " "; } cerr << "]"; }
template <class T> void print(set <T> v) { cerr << "[ "; for (T i : v) { print(i); cerr << " "; } cerr << "]"; }
template <class T> void print(multiset <T> v) { cerr << "[ "; for (T i : v) { print(i); cerr << " "; } cerr << "]"; }
template <class T, class V> void print(map <T, V> v) { cerr << "[ "; for (auto i : v) { print(i); cerr << " "; } cerr << "]"; }
template <class T> void print(queue <T> q) { cerr << "[ "; while (!q.empty()) { print(q.front()); cerr << " "; q.pop(); } cerr << "]"; }
template <class T> void print(priority_queue <T> q) { cerr << "[ "; while (!q.empty()) { print(q.top()); cerr << " "; q.pop(); } cerr << "]"; }
template <class T> void print(int n__, T arr[]) { cerr << "[ "; for (int i = 0; i <= n__; i++) { print(arr[i]); cerr << " "; } cerr << "]"; }

ll gcdll(ll a, ll b) { return b == 0 ? a : gcdll(b, a % b); }

long long mult(long long a, long long b)
{
	return (a * b) % mod;
}

long long binpow(long long a, long long b) {
	long long res = 1;
	a %= mod;
	while (b > 0) {
		if (b & 1) res = res * a % mod;
		a = a * a % mod;
		b >>= 1;
	}
	return res;
}

long long m_inverse(long long n) {
	return binpow(n, mod - 2);
}

long long divide(long long a, long long b) {
	return (a % mod * m_inverse(b)) % mod;
}

long long sub(long long a, long long b)
{
	if (a - b >= 0)return a - b;
	else return a - b + mod;
}

long long add(long long a, long long b)
{
	if (a + b >= mod)return a + b - mod;
	else return a + b;
}

const int LOG = 21;
const int N = 1e6 + 5;
const ll inf = 1e18;

ll n, m, k;

ll c[N], r[N];
ll sum_r[N], sum_c[N];

ll a(int i, int j)
{
	return add(j, mult(i - 1, m));
}

void solve()
{
	vector<pair<int, int>>row, col;
	cin >> n >> m >> k;
	fill(r + 1, r + 1 + n, 1);
	fill(c + 1, c + 1 + m, 1);

	for (int i = 1; i <= k; i++)
	{
		char ch;
		int x;
		ll y;
		cin >> ch >> x >> y;
		if (ch == 'R')
		{
			r[x] = mult(r[x], y);
		}
		else {
			c[x] = mult(c[x], y);
		}
	}

	ll ans = 0;
	ll s = 0;
	for (int i = 1; i <= n; i++)
		s = add(s, mult(i - 1, r[i]));
	s = mult(s, m);
	for (int i = 1; i <= m; i++)
		ans = add(ans, mult(s, c[i]));
	s = 0;
	for (int i = 1; i <= m; i++)
		s = add(s, mult(i, c[i]));
	for (int i = 1; i <= n; i++)
		ans = add(ans, mult(s, r[i]));
	cout << ans << endl;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int t = 1;
	//cin >> t;
	while (t--)
	{
		solve();
	}
	return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...