제출 #1273462

#제출 시각아이디문제언어결과실행 시간메모리
1273462chanhchuong123Automobil (COCI17_automobil)C++20
100 / 100
8 ms8260 KiB
#include<bits/stdc++.h>
using namespace std;

const bool multiTest = false;
#define task "C"
#define fi first
#define se second
#define MASK(i) (1LL << (i))
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define BIT(mask, i) ((mask) >> (i) & 1)

template<typename T1, typename T2> bool minimize(T1 &a, T2 b) {
	if (a > b) a = b; else return 0; return 1;
}
template<typename T1, typename T2> bool maximize(T1 &a, T2 b) {
	if (a < b) a = b; else return 0; return 1;
}

const int MOD = 1e9 + 7;
const int MAX = 1000100;
int n, m, k, ans;
int row[MAX];
int col[MAX];

int sumBaseRow(int pos) {
    return (m * (m + 1LL) / 2 % MOD + (pos - 1LL) * m % MOD * m % MOD) % MOD;
}

int sumBaseCol(int pos) {
    return (1LL * pos * n % MOD + (n - 1LL) * n / 2 % MOD * m) % MOD;
}

void process(void) {
    cin >> n >> m >> k;
    if (n % 2 == 0 || m % 2 == 0) ans = (1LL * n * m / 2 % MOD) * ((1LL * n * m + 1) % MOD) % MOD; else ans = (1LL * n * m % MOD) * ((1LL * n * m + 1) / 2 % MOD) % MOD;

    for (int i = 1; i <= n; ++i) {
        row[i] = 1;
    }
    for (int j = 1; j <= m; ++j) {
        col[j] = 1;
    }

    vector<int> rows, cols, zeroRows, zeroCols;
    while (k--) {
        char type; int X, Y; cin >> type >> X >> Y;
        if (Y == 1) continue;
        if (Y == 0) {
            (type == 'R' ? zeroRows: zeroCols).push_back(X);
            continue;
        }
        if (type == 'R') {
            ans -= 1LL * sumBaseRow(X) * row[X] % MOD;
            if (ans < 0) ans += MOD;
            rows.push_back(X);
            row[X] = 1LL * row[X] * Y % MOD;
            ans = (ans + 1LL * sumBaseRow(X) * row[X]) % MOD;
        } else {
            ans -= 1LL * sumBaseCol(X) * col[X] % MOD;
            if (ans < 0) ans += MOD;
            cols.push_back(X);
            col[X] = 1LL * col[X] * Y % MOD;
            ans = (ans + 1LL * sumBaseCol(X) * col[X]) % MOD;
        }
    }

    sort(all(rows));
    sort(all(cols));
    rows.resize(unique(all(rows)) - rows.begin());
    cols.resize(unique(all(cols)) - cols.begin());
    for (int &r: rows) for (int &c: cols) {
        ans -= ((r - 1LL) * m + c) % MOD * ((row[r] + col[c] - 1) % MOD) % MOD;
        if (ans < 0) ans += MOD;
        ans = (ans + ((r - 1LL) * m + c) % MOD * (1LL * row[r] * col[c] % MOD) % MOD) % MOD;
    }

    sort(all(zeroRows));
    sort(all(zeroCols));
    zeroRows.resize(unique(all(zeroRows)) - zeroRows.begin());
    zeroCols.resize(unique(all(zeroCols)) - zeroCols.begin());
    for (int &r: zeroRows) {
        ans -= 1LL * sumBaseRow(r) * row[r] % MOD;
        if (ans < 0) ans += MOD;
    }
    for (int &c: zeroCols) {
        ans -= 1LL * sumBaseCol(c) * col[c] % MOD;
        if (ans < 0) ans += MOD;
    }

    for (int &r: zeroRows) for (int &c: cols) {
        ans = (ans + ((r - 1LL) * m + c) % MOD * row[r] % MOD) % MOD; ans -= ((r - 1LL) * m + c) % MOD * (1LL * row[r] * col[c] % MOD) % MOD;
        if (ans < 0) ans += MOD;
    }
    for (int &r: rows) for (int &c: zeroCols) {
        ans = (ans + ((r - 1LL) * m + c) % MOD * (col[c]) % MOD) % MOD; ans -= ((r - 1LL) * m + c) % MOD * (1LL * row[r] * col[c] % MOD) % MOD;
        if (ans < 0) ans += MOD;
    }
    for (int &r: zeroRows) for (int &c: zeroCols) {
        ans = (ans + ((r - 1LL) * m + c) % MOD * (row[r] + col[c] + 1) % MOD) % MOD; ans -= ((r - 1LL) * m + c) % MOD * (1LL * row[r] * col[c] % MOD) % MOD;
        if (ans < 0) ans += MOD;
    }

    cout << ans;
}

int main(void) {
	ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
	if (fopen(task".inp", "r")) {
		freopen(task".inp", "r",  stdin);
		freopen(task".out", "w", stdout);
	}

	int nTest = 1; if (multiTest) cin >> nTest;
	while (nTest--) {
		process();
	}

	return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

automobil.cpp: In function 'int main()':
automobil.cpp:110:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  110 |                 freopen(task".inp", "r",  stdin);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
automobil.cpp:111:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  111 |                 freopen(task".out", "w", stdout);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...