#include <bits/stdc++.h>
#define tt cin.tie(0), cout.tie(0), ios_base::sync_with_stdio(0)
#define fo freopen((NAME+".INP").c_str(), "r", stdin), freopen((NAME+".OUT").c_str(), "w", stdout)
#define ll long long
#define ull unsigned long long
#define i128 __int128
#define db long double
#define sz(a) ((int)(a).size())
#define pb emplace_back
#define pf emplace_front
#define pob pop_back
#define pof pop_front
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define ins emplace
#define mp make_pair
using namespace std;
const int MOD = 1e9+7, MAXN = 1e6+5;
const string NAME = "";
int k,rs,row[MAXN],col[MAXN];
ll n,m;
vector<int> R,C;
inline void add(int& a, int b){
a+=b;
if(a>=MOD) a-=MOD;
}
inline void sub(int& a, int b){
a-=b;
if(a<0) a+=MOD;
}
int getsum(ll l, ll r, int dist){
ll a=l+r, b=(r-l)/dist+1;
if(b&1) a>>=1;
else b>>=1;
a%=MOD, b%=MOD;
return a*b%MOD;
}
int main()
{
tt;
if(fopen((NAME + ".INP").c_str(), "r")) fo;
cin >> n >> m >> k;
fill(row+1,row+n+1,1);
fill(col+1,col+m+1,1);
for(int i = 1; i<=k; ++i){
char type;
int x,y;
cin >> type >> x >> y;
if(type=='R') row[x]=1ll*row[x]*y%MOD, R.pb(x);
else col[x]=1ll*col[x]*y%MOD, C.pb(x);
}
sort(R.begin(),R.end());
R.resize(unique(R.begin(),R.end())-R.begin());
sort(C.begin(),C.end());
C.resize(unique(C.begin(),C.end())-C.begin());
if((n*m)&1) rs=(n*m%MOD)*((n*m+1)/2%MOD)%MOD;
else rs=(n*m/2%MOD)*((n*m+1)%MOD)%MOD;
for(int& x : C)
sub(rs,getsum(x,x+(n-1)*m,m)), add(rs,1ll*col[x]*getsum(x,x+(n-1)*m,m)%MOD);
for(int& x : R){
int sum=getsum((x-1)*m+1,x*m,1);
for(int& y : C){
int val=((x-1)*m+y)%MOD, mul=1ll*row[x]*col[y]%MOD;
sub(rs,1ll*col[y]*val%MOD), add(rs,1ll*mul*val%MOD);
sub(sum,val);
}
sub(rs,sum), add(rs,1ll*row[x]*sum%MOD);
}
cout << rs;
}
Compilation message (stderr)
automobil.cpp: In function 'int main()':
automobil.cpp:3:19: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
3 | #define fo freopen((NAME+".INP").c_str(), "r", stdin), freopen((NAME+".OUT").c_str(), "w", stdout)
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
automobil.cpp:43:45: note: in expansion of macro 'fo'
43 | if(fopen((NAME + ".INP").c_str(), "r")) fo;
| ^~
automobil.cpp:3:63: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
3 | #define fo freopen((NAME+".INP").c_str(), "r", stdin), freopen((NAME+".OUT").c_str(), "w", stdout)
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
automobil.cpp:43:45: note: in expansion of macro 'fo'
43 | if(fopen((NAME + ".INP").c_str(), "r")) fo;
| ^~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |