#include <bits/stdc++.h>
using namespace std;
const int MOD=1e9+7,N=1e6+5;
long long r[N],c[N];
vector<int> rs,cs;
int n,m,k;
long long inv2;
long long poww(long long b,long long p)
{
if(p==0) return 1;
if(p&1) return (b*poww(b,p-1))%MOD;
return poww((b*b)%MOD,p/2);
}
long long get(long long st,long long en,long long n)
{
return ((((st+en)%MOD*n)%MOD)*inv2)%MOD;
}
int main()
{
inv2=poww(2,MOD-2);
cin >> n >> m >> k;
for(int i=1;i<=n;i++)
r[i]=1;
for(int i=1;i<=m;i++)
c[i]=1;
for(int i=0;i<k;i++)
{
char x; int a,b;
cin >> x >> a >> b;
if(x=='R')
{
rs.push_back(a);
r[a]=(r[a]*b)%MOD;
}
else
{
cs.push_back(b);
c[a]=(c[a]*b)%MOD;
}
}
sort(rs.begin(),rs.end()); rs.erase(unique(rs.begin(),rs.end()),rs.end());
sort(cs.begin(),cs.end()); cs.erase(unique(cs.begin(),cs.end()),cs.end());
long long ans=0;
for(int i=1;i<=n;i++)
{
ans+=(get(1LL*(i-1)*m+1,1LL*i*m,m)*r[i])%MOD;
ans%=MOD;
}
for(int i=1;i<=m;i++)
{
ans+=(get(i,i+1LL*(n-1)*m,n)*(c[i]-1))%MOD;
ans=(ans+MOD)%MOD;
}
for(int i:rs)
{
for(int j:cs)
{
long long elem=(1LL*(i-1)*m+j)%MOD;
ans-=(elem*(r[i]+c[j]-1))%MOD;
ans+=((elem*r[i])%MOD)*c[j];
ans%=MOD;
ans=(ans+MOD)%MOD;
}
}
cout << ans << endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
7 ms |
504 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Runtime error |
6 ms |
504 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
3 |
Runtime error |
6 ms |
376 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
4 |
Runtime error |
7 ms |
504 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
5 |
Runtime error |
6 ms |
508 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
6 |
Runtime error |
6 ms |
504 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
7 |
Runtime error |
7 ms |
504 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
8 |
Runtime error |
7 ms |
504 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
9 |
Runtime error |
7 ms |
504 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
10 |
Runtime error |
7 ms |
504 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
11 |
Runtime error |
14 ms |
5368 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
12 |
Runtime error |
33 ms |
17400 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
13 |
Runtime error |
8 ms |
1656 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
14 |
Runtime error |
35 ms |
20216 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
15 |
Runtime error |
33 ms |
18040 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
16 |
Runtime error |
52 ms |
32248 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
17 |
Runtime error |
54 ms |
32120 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
18 |
Runtime error |
55 ms |
32120 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
19 |
Runtime error |
53 ms |
32120 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
20 |
Runtime error |
54 ms |
32120 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |