Submission #1357737

#TimeUsernameProblemLanguageResultExecution timeMemory
1357737po_rag526Automobil (COCI17_automobil)C++20
20 / 100
6 ms15940 KiB
#include <bits/stdc++.h>
using namespace std;

using int64 = long long;
const int64 MOD = 1000000007LL;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int N, M, K;
    cin >> N >> M >> K;

    vector<int64> row(N + 1, 1), col(M + 1, 1);

    auto norm = [](int64 x) {
        x %= MOD;
        if (x < 0) x += MOD;
        return x;
    };

    int64 sumR = N % MOD;
    int64 sumIR = (1LL * N * (N - 1) / 2) % MOD;
    int64 sumC = M % MOD;
    int64 sumJC = (1LL * M * (M + 1) / 2) % MOD;

    for (int i = 0; i < K; i++) {
        char type;
        int x;
        int64 y;
        cin >> type >> x >> y;
        y %= MOD;

        if (type == 'R') {
            int64 old = row[x];
            int64 diff = norm(y - old);
            row[x] = y;
            sumR = norm(sumR + diff);
            sumIR = norm(sumIR + 1LL * (x - 1) % MOD * diff);
        } else {
            int64 old = col[x];
            int64 diff = norm(y - old);
            col[x] = y;
            sumC = norm(sumC + diff);
            sumJC = norm(sumJC + 1LL * x % MOD * diff);
        }
    }

    int64 ans = 0;
    ans = (ans + (1LL * M % MOD) * sumIR % MOD * sumC) % MOD;
    ans = (ans + sumR * sumJC) % MOD;

    cout << ans % MOD << '\n';
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...