답안 #960026

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
960026 2024-04-09T14:01:05 Z Ariadna Topovi (COCI15_topovi) C++14
120 / 120
1203 ms 39944 KB
#include <bits/stdc++.h>
#define ll long long

using namespace std;

map<int, int> xor_rows, xor_columns;
map<int, int> cnt_rows, cnt_columns;
map<pair<int, int>, int> rooks;

void change(int r, int c, ll& total, int n) {
    total -= n-cnt_columns[xor_rows[r]];
    total -= n-cnt_rows[xor_columns[c]];
    if (xor_rows[r] ^ xor_columns[c]) ++total;

    cnt_rows[xor_rows[r]]--;
    xor_rows[r] ^= rooks[{r, c}];
    cnt_rows[xor_rows[r]]++;

    cnt_columns[xor_columns[c]]--;
    xor_columns[c] ^= rooks[{r, c}];
    cnt_columns[xor_columns[c]]++;

    total += n-cnt_columns[xor_rows[r]];
    total += n-cnt_rows[xor_columns[c]];
    if (xor_rows[r] ^ xor_columns[c]) --total;
}

int main() {
    int n, k, p;
    cin >> n >> k >> p;
    cnt_rows[0] = cnt_columns[0] = n;

    ll total = 0;
    while (k--) {
        int r, c, x;
        cin >> r >> c >> x;
        rooks[{r, c}] = x;
        change(r, c, total, n);
    }

    while (p--) {
        int r1, c1, r2, c2;
        cin >> r1 >> c1 >> r2 >> c2;

        change(r1, c1, total, n);
        rooks[{r2, c2}] = rooks[{r1, c1}];
        change(r2, c2, total, n);
        rooks[{r1, c1}] = 0;

        cout << total << '\n';
    }

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 432 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 145 ms 5960 KB Output is correct
7 Correct 111 ms 5304 KB Output is correct
8 Correct 88 ms 4436 KB Output is correct
9 Correct 92 ms 4468 KB Output is correct
10 Correct 103 ms 4692 KB Output is correct
11 Correct 1167 ms 39944 KB Output is correct
12 Correct 1151 ms 39540 KB Output is correct
13 Correct 1135 ms 39540 KB Output is correct
14 Correct 1167 ms 39416 KB Output is correct
15 Correct 1203 ms 39480 KB Output is correct
16 Correct 1146 ms 39464 KB Output is correct
17 Correct 1149 ms 39508 KB Output is correct
18 Correct 1149 ms 39520 KB Output is correct
19 Correct 1163 ms 39452 KB Output is correct
20 Correct 1153 ms 39312 KB Output is correct