Submission #104272

# Submission time Handle Problem Language Result Execution time Memory
104272 2019-04-04T15:37:41 Z Kewo Automobil (COCI17_automobil) C++17
85 / 100
45 ms 31864 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;
		}
	}
	assert(ans >= 0);
	cout << ans;
}
# Verdict Execution time Memory Grader output
1 Correct 19 ms 16000 KB Output is correct
2 Correct 22 ms 16000 KB Output is correct
3 Correct 18 ms 16000 KB Output is correct
4 Runtime error 44 ms 31864 KB Execution killed with signal 11 (could be triggered by violating memory limits)
5 Runtime error 45 ms 31836 KB Execution killed with signal 11 (could be triggered by violating memory limits)
6 Correct 19 ms 16000 KB Output is correct
7 Correct 19 ms 16000 KB Output is correct
8 Correct 21 ms 16000 KB Output is correct
9 Correct 21 ms 16000 KB Output is correct
10 Runtime error 45 ms 31864 KB Execution killed with signal 11 (could be triggered by violating memory limits)
11 Correct 24 ms 16256 KB Output is correct
12 Correct 30 ms 16000 KB Output is correct
13 Correct 17 ms 16000 KB Output is correct
14 Correct 26 ms 16000 KB Output is correct
15 Correct 27 ms 16120 KB Output is correct
16 Correct 31 ms 16000 KB Output is correct
17 Correct 33 ms 15992 KB Output is correct
18 Correct 29 ms 16016 KB Output is correct
19 Correct 32 ms 16000 KB Output is correct
20 Correct 31 ms 16000 KB Output is correct