답안 #104274

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
104274 2019-04-04T15:39:06 Z Kewo Automobil (COCI17_automobil) C++17
100 / 100
37 ms 16248 KB
#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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 16000 KB Output is correct
2 Correct 19 ms 16000 KB Output is correct
3 Correct 21 ms 16008 KB Output is correct
4 Correct 16 ms 16092 KB Output is correct
5 Correct 20 ms 16000 KB Output is correct
6 Correct 20 ms 16000 KB Output is correct
7 Correct 20 ms 16000 KB Output is correct
8 Correct 18 ms 16000 KB Output is correct
9 Correct 18 ms 16000 KB Output is correct
10 Correct 19 ms 16000 KB Output is correct
11 Correct 19 ms 15992 KB Output is correct
12 Correct 30 ms 16248 KB Output is correct
13 Correct 18 ms 16000 KB Output is correct
14 Correct 22 ms 16000 KB Output is correct
15 Correct 25 ms 16000 KB Output is correct
16 Correct 37 ms 16000 KB Output is correct
17 Correct 30 ms 16080 KB Output is correct
18 Correct 28 ms 16000 KB Output is correct
19 Correct 30 ms 16000 KB Output is correct
20 Correct 32 ms 16120 KB Output is correct