답안 #743565

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
743565 2023-05-17T13:52:09 Z bgnbvnbv Automobil (COCI17_automobil) C++14
100 / 100
17 ms 15956 KB
#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=1e6+10;
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

automobil.cpp: In function 'void solve()':
automobil.cpp:80:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   80 |     for(int i=0;i<vecr.size();i++)
      |                 ~^~~~~~~~~~~~
automobil.cpp:84:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   84 |         for(int j=0;j<vecc.size();j++)
      |                     ~^~~~~~~~~~~~
automobil.cpp:94:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   94 |     for(int i=0;i<vecc.size();i++)
      |                 ~^~~~~~~~~~~~
automobil.cpp:98:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   98 |         for(int j=0;j<vecr.size();j++)
      |                     ~^~~~~~~~~~~~
automobil.cpp:108:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  108 |     for(int i=0;i<vecr.size();i++)
      |                 ~^~~~~~~~~~~~
automobil.cpp:110:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  110 |         for(int j=0;j<vecc.size();j++)
      |                     ~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 2 ms 380 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 4 ms 2772 KB Output is correct
12 Correct 11 ms 8660 KB Output is correct
13 Correct 2 ms 852 KB Output is correct
14 Correct 10 ms 10068 KB Output is correct
15 Correct 12 ms 9072 KB Output is correct
16 Correct 15 ms 15956 KB Output is correct
17 Correct 16 ms 15896 KB Output is correct
18 Correct 16 ms 15956 KB Output is correct
19 Correct 17 ms 15956 KB Output is correct
20 Correct 16 ms 15956 KB Output is correct