# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
743564 | bgnbvnbv | Automobil (COCI17_automobil) | C++14 | 4 ms | 3668 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#define TASKNAME "codeforce"
#define pb push_back
#define pli pair<ll,ll>
#define fi first
#define se second
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
using ll=long long;
const ll maxN=2e5;
const ll inf=1e18;
const ll mod=1e9+7;
ll get(ll l,ll r,ll s)
{
// return (r+l)*((r-l)/s+1)/2;
ll sum=(r+l);
ll cnt=(r-l)/s+1;
if(sum%2==0)
{
sum/=2;
sum%=mod;
cnt%=mod;
return sum*cnt%mod;
}
else
{
cnt/=2;
sum%=mod;
cnt%=mod;
return sum*cnt%mod;
}
}
ll n,m,k;
ll mulr[maxN],mulc[maxN];
vector<pli>vecr,vecc;
void solve()
{
cin >> n >> m >> k;
for(int i=1;i<=n;i++) mulr[i]=1;
for(int i=1;i<=m;i++) mulc[i]=1;
for(int i=1;i<=k;i++)
{
char t;
cin >> t;
if(t=='R')
{
ll x,y;
cin >> x >> y;
mulr[x]*=y;
mulr[x]%=mod;
}
else
{
ll x,y;
cin >> x >> y;
mulc[x]*=y;
mulc[x]%=mod;
}
}
for(int i=1;i<=n;i++)
{
if(mulr[i]!=1)
{
vecr.pb({i,mulr[i]});
}
}
for(int i=1;i<=m;i++)
{
if(mulc[i]!=1)
{
vecc.pb({i,mulc[i]});
}
}
ll sum=0;
for(int i=1;i<=n;i++)
{
sum+=get((i-1)*m+1,i*m,1);
if(sum>=mod) sum-=mod;
}
for(int i=0;i<vecr.size();i++)
{
ll r=vecr[i].fi;
ll cc=get((r-1)*m+1,r*m,1);
for(int j=0;j<vecc.size();j++)
{
ll c=vecc[j].fi;
cc-=((r-1)*m+c)%mod;
if(cc<0) cc+=mod;
}
cc=cc*(vecr[i].se-1)%mod;
sum+=cc;
if(sum>=mod) sum-=mod;
}
for(int i=0;i<vecc.size();i++)
{
ll c=vecc[i].fi;
ll cc=get(c,c+(n-1)*m,m);
for(int j=0;j<vecr.size();j++)
{
ll r=vecr[j].fi;
cc-=((r-1)*m+c)%mod;
if(cc<0) cc+=mod;
}
cc=cc*(vecc[i].se-1)%mod;
sum+=cc;
if(sum>=mod) sum-=mod;
}
for(int i=0;i<vecr.size();i++)
{
for(int j=0;j<vecc.size();j++)
{
ll r=vecr[i].fi;
ll c=vecc[j].fi;
ll mul=vecr[i].se*vecc[j].se%mod;
sum+=(((r-1)*m+c)%mod)*(mul-1)%mod;
sum%=mod;
if(sum<0) sum+=mod;
}
}
cout << sum;
}
int main()
{
fastio
//freopen(TASKNAME".INP","r",stdin);
//freopen(TASKNAME".OUT","w",stdout);
solve();
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |