Submission #104269

# Submission time Handle Problem Language Result Execution time Memory
104269 2019-04-04T15:33:52 Z Kewo Automobil (COCI17_automobil) C++17
85 / 100
27 ms 16068 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 int mod = (int)(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;
}

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;
			ans %= mod;
			ans += get(i, j);
			ans %= mod;
		}
	}
	cout << ans;
}
# Verdict Execution time Memory Grader output
1 Correct 20 ms 16048 KB Output is correct
2 Correct 21 ms 16000 KB Output is correct
3 Correct 18 ms 16000 KB Output is correct
4 Incorrect 19 ms 16000 KB Output isn't correct
5 Incorrect 18 ms 16000 KB Output isn't correct
6 Correct 17 ms 16000 KB Output is correct
7 Correct 22 ms 16048 KB Output is correct
8 Correct 20 ms 15952 KB Output is correct
9 Correct 20 ms 15944 KB Output is correct
10 Incorrect 20 ms 16000 KB Output isn't correct
11 Correct 20 ms 16000 KB Output is correct
12 Correct 25 ms 16048 KB Output is correct
13 Correct 20 ms 16000 KB Output is correct
14 Correct 23 ms 15992 KB Output is correct
15 Correct 26 ms 16000 KB Output is correct
16 Correct 27 ms 16000 KB Output is correct
17 Correct 26 ms 16000 KB Output is correct
18 Correct 26 ms 16068 KB Output is correct
19 Correct 25 ms 16068 KB Output is correct
20 Correct 27 ms 16000 KB Output is correct