Submission #736219

# Submission time Handle Problem Language Result Execution time Memory
736219 2023-05-05T10:29:32 Z Nhoksocqt1 Automobil (COCI17_automobil) C++17
90 / 100
15 ms 16000 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) {
    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:62:36: warning: narrowing conversion of 'mulr[i]' from 'll' {aka 'long long int'} to 'int' [-Wnarrowing]
   62 |             qr[nRow++] = {i, mulr[i]};
      |                              ~~~~~~^
automobil.cpp:71:36: warning: narrowing conversion of 'mulc[i]' from 'll' {aka 'long long int'} to 'int' [-Wnarrowing]
   71 |             qc[nCol++] = {i, mulc[i]};
      |                              ~~~~~~^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 356 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 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 Incorrect 4 ms 3028 KB Output isn't correct
12 Correct 12 ms 11004 KB Output is correct
13 Correct 1 ms 1108 KB Output is correct
14 Incorrect 10 ms 13728 KB Output isn't correct
15 Correct 7 ms 9812 KB Output is correct
16 Correct 11 ms 15916 KB Output is correct
17 Correct 13 ms 15920 KB Output is correct
18 Correct 11 ms 15956 KB Output is correct
19 Correct 15 ms 16000 KB Output is correct
20 Correct 12 ms 15956 KB Output is correct