| # | Time | Username | Problem | Language | Result | Execution time | Memory | 
|---|---|---|---|---|---|---|---|
| 736221 | Nhoksocqt1 | Automobil (COCI17_automobil) | C++17 | 11 ms | 15996 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>
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 (stderr)
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
