답안 #736221

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
736221 2023-05-05T10:33:58 Z Nhoksocqt1 Automobil (COCI17_automobil) C++17
100 / 100
11 ms 15996 KB
#include<bits/stdc++.h>
using namespace std;

#define inf 0x3f3f3f3f
#define sz(x) int((x).size())
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> ii;

template<class X, class Y>
    inline bool maximize(X &x, const Y &y) {return (x < y ? x = y, 1 : 0);}
template<class X, class Y>
    inline bool minimize(X &x, const Y &y) {return (x > y ? x = y, 1 : 0);}

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int Random(int l, int r) {
    return uniform_int_distribution<int>(l, r)(rng);
}

const int MAXQ = 1003;
const int MAXN = 1e6+6;
const int modl = 1e9+7;

struct Query {
    int a, b;
} qr[MAXQ], qc[MAXQ];

ll mulr[MAXN], mulc[MAXN], row, col;
int nRow, nCol, numQuery;

inline ll C2(ll n) {
    return (n % 2) ? (n + 1) / 2 % modl * (n % modl) % modl : n / 2 % modl * ((n + 1) % modl) % modl;
}

inline ll calc(ll l, ll r, ll k) {
    if((r + l) & 1)
        return (r + l) % modl * ((r - l + k) / k / 2 % modl) % modl;

    return (r + l) / 2 % modl * ((r - l + k) / k % modl) % modl;
}

void process() {
    cin >> row >> col >> numQuery;

    for (int i = 1; i <= max(row, col); ++i)
        mulr[i] = mulc[i] = 1;

    ll res = C2(1LL * row * col);
    for (int t = 0; t < numQuery; ++t) {
        int a, b;
        char c;
        cin >> c >> a >> b;
        if(c == 'R') {
            mulr[a] = mulr[a] * b % modl;
        } else {
            mulc[a] = mulc[a] * b % modl;
        }
    }

    nRow = nCol = 0;
    for (int i = 1; i <= row; ++i) {
        if(mulr[i] != 1) {
            res -= (C2(i * col) - C2((i - 1) * col) + modl) % modl;
            qr[nRow++] = {i, mulr[i]};
            res += (C2(i * col) - C2((i - 1) * col) + modl) % modl * mulr[i] % modl;
            //cout << (C2(i * col) - C2((i - 1) * col) + modl) % modl << ' ' << mulr[i] << '\n';
        }
    }

    for (int i = 1; i <= col; ++i) {
        if(mulc[i] != 1) {
            res -= calc(i, (row - 1) * col + i, col);
            qc[nCol++] = {i, mulc[i]};
            res += calc(i, (row - 1) * col + i, col) * mulc[i] % modl;
            //cout << calc(i, (row - 1) * col + i, col) << ' ' << mulc[i] << '\n';
        }
    }

    for (int i = 0; i < nRow; ++i) {
        for (int j = 0; j < nCol; ++j) {
            ll x = (qr[i].a - 1) * col + qc[j].a;

            x %= modl;
            //cout << qr[i].a << ' ' << qc[j].a << ' ' << qr[i].b << ' ' << qc[j].b << '\n';
            res -= x * (qr[i].b + qc[j].b) % modl;
            res += x * qr[i].b % modl * qc[j].b % modl + x;
        }
    }

    res = (res % modl + modl) % modl;
    cout << res;
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    process();
    return 0;
}

Compilation message

automobil.cpp: In function 'void process()':
automobil.cpp:65:36: warning: narrowing conversion of 'mulr[i]' from 'll' {aka 'long long int'} to 'int' [-Wnarrowing]
   65 |             qr[nRow++] = {i, mulr[i]};
      |                              ~~~~~~^
automobil.cpp:74:36: warning: narrowing conversion of 'mulc[i]' from 'll' {aka 'long long int'} to 'int' [-Wnarrowing]
   74 |             qc[nCol++] = {i, mulc[i]};
      |                              ~~~~~~^
# 결과 실행 시간 메모리 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 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 3 ms 3028 KB Output is correct
12 Correct 10 ms 11052 KB Output is correct
13 Correct 2 ms 1108 KB Output is correct
14 Correct 7 ms 13652 KB Output is correct
15 Correct 7 ms 9812 KB Output is correct
16 Correct 10 ms 15956 KB Output is correct
17 Correct 11 ms 15996 KB Output is correct
18 Correct 11 ms 15956 KB Output is correct
19 Correct 11 ms 15992 KB Output is correct
20 Correct 10 ms 15956 KB Output is correct