#include<bits/stdc++.h>
#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define dec(x, y) fixed << setprecision((y)) << (x)
#define xx first
#define yy second
#define srt(v) sort((v).begin(), (v).end())
#define srtr(v) sort((v).rbegin(), (v).rend())
#define pb push_back
#define popb pop_back
#define sz(a) (int)(a).size()
#define len(a) (int)(a).length()
#define mp make_pair
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const ll mod=(ll)1e9+7LL;
ll n, m;
int k;
map<ll, ll> rd, kl;
map<ll, bool> uzrd, uzkl;
ll suma;
int main() {
ios;
cin >> n >> m >> k;
for(int i=0; i<k; i++) {
char c; ll d, kol;
cin >> c >> d >> kol;
if(c=='R') {
if(!uzrd[d]) rd[d]=kol;
else rd[d]*=kol;
uzrd[d]=1;
}
else {
if(!uzkl[d]) kl[d]=kol;
else kl[d]*=kol;
uzkl[d]=1;
}
}
suma=(n*m+1LL)*(n*m)/2LL;
suma%=mod;
for(auto it=rd.begin(); it!=rd.end(); it++) {
ll d=it->first, kol=it->second;
if(uzrd[d]) suma+=((d*m+1LL)*(d*m)/2LL%mod-((d-1LL)*m+1LL)%mod*((d-1LL)*m)/2LL)%mod*(kol-1LL)%mod;
}
for(auto it=kl.begin(); it!=kl.end(); it++) {
ll d=it->first, kol=it->second;
if(uzkl[d]) suma+=(n*(n-1LL)*m/2LL%mod+d*n%mod)%mod*(kol-1LL)%mod;
}
//cout << suma;
for(auto it=rd.begin(); it!=rd.end(); it++) {
for(auto it1=kl.begin(); it1!=kl.end(); it1++) {
ll d=it->first, kol=it->second;
ll d1=it1->first, kol1=it1->second;
if(!uzrd[d] || !uzkl[d1]) continue;
suma-=(m*(d-1LL)+d1)%mod*(kol+kol1-1LL)%mod;
suma+=(m*(d-1LL)+d1)%mod*kol%mod*kol1%mod;
}
}
cout << suma;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
2 |
Incorrect |
3 ms |
332 KB |
Output isn't correct |
3 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
4 |
Incorrect |
3 ms |
384 KB |
Output isn't correct |
5 |
Incorrect |
3 ms |
332 KB |
Output isn't correct |
6 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
7 |
Incorrect |
6 ms |
384 KB |
Output isn't correct |
8 |
Incorrect |
2 ms |
332 KB |
Output isn't correct |
9 |
Incorrect |
4 ms |
332 KB |
Output isn't correct |
10 |
Incorrect |
7 ms |
332 KB |
Output isn't correct |
11 |
Incorrect |
5 ms |
332 KB |
Output isn't correct |
12 |
Incorrect |
12 ms |
432 KB |
Output isn't correct |
13 |
Incorrect |
3 ms |
332 KB |
Output isn't correct |
14 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
15 |
Incorrect |
8 ms |
332 KB |
Output isn't correct |
16 |
Incorrect |
14 ms |
332 KB |
Output isn't correct |
17 |
Incorrect |
14 ms |
432 KB |
Output isn't correct |
18 |
Incorrect |
13 ms |
432 KB |
Output isn't correct |
19 |
Incorrect |
13 ms |
432 KB |
Output isn't correct |
20 |
Incorrect |
13 ms |
332 KB |
Output isn't correct |