답안 #956352

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
956352 2024-04-01T16:48:49 Z Ariadna Topovi (COCI15_topovi) C++14
30 / 120
407 ms 65536 KB
#include <bits/stdc++.h>
#define ll long long

using namespace std;

const int MAX_ROOKS = 2e5;

int main() {
    int n, k, p;
    cin >> n >> k >> p;
    unordered_map<int, int> rows, columns;
    rows.reserve(MAX_ROOKS);
    columns.reserve(MAX_ROOKS);
    map<pair<int, int>, int> rooks;
    while (k--) {
        int r, c, x;
        cin >> r >> c >> x;
        --r; --c;
        rows[r] ^= x;
        columns[c] ^= x;
        rooks[{r, c}] = x;
    }
    ll total = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            if (((rows[i] ^ rooks[{i, j}]) ^ (columns[j] ^ rooks[{i, j}])) > 0) ++total;
        }
    }
    while (p--) {
        int r1, c1, r2, c2;
        cin >> r1 >> c1 >> r2 >> c2; 
        --r1; --r2; --c1; --c2;
        for (int i = 0; i < n; ++i) {
            if (i == c1) continue;
            if (((columns[i] ^ rooks[{r1, i}]) ^ (rows[r1] ^ rooks[{r1, i}])) > 0 && ((columns[i] ^ rooks[{r1, i}]) ^ ((rows[r1] ^ rooks[{r1, i}]) ^ rooks[{r1, c1}])) == 0) --total;
            else if (((columns[i] ^ rooks[{r1, i}]) ^ (rows[r1] ^ rooks[{r1, i}])) == 0 && ((columns[i] ^ rooks[{r1, i}]) ^ ((rows[r1] ^ rooks[{r1, i}]) ^ rooks[{r1, c1}])) > 0) ++total;
        }
        for (int i = 0; i < n; ++i) {
            if (i == r1) continue;
            if (((columns[c1] ^ rooks[{i, c1}]) ^ (rows[i] ^ rooks[{i, c1}])) > 0 && (((columns[c1] ^ rooks[{i, c1}]) ^ rooks[{r1, c1}]) ^ (rows[i] ^ rooks[{i, c1}])) == 0) --total;
            else if (((columns[c1] ^ rooks[{i, c1}]) ^ (rows[i] ^ rooks[{i, c1}])) == 0 && (((columns[c1] ^ rooks[{i, c1}]) ^ rooks[{r1, c1}]) ^ (rows[i] ^ rooks[{i, c1}])) > 0) ++total;
        }
        rows[r1] ^= rooks[{r1, c1}];
        columns[c1] ^= rooks[{r1, c1}];
        rooks[{r2, c2}] = rooks[{r1, c1}];
        rooks[{r1, c1}] = 0;
        for (int i = 0; i < n; ++i) {
            if (i == c2) continue;
            if (((columns[i] ^ rooks[{r2, i}]) ^ (rows[r2] ^ rooks[{r2, i}])) == 0 && ((columns[i] ^ rooks[{r2, i}]) ^ ((rows[r2] ^ rooks[{r2, i}]) ^ rooks[{r2, c2}])) > 0) ++total;
            else if (((columns[i] ^ rooks[{r2, i}]) ^ (rows[r2] ^ rooks[{r2, i}])) > 0 && ((columns[i] ^ rooks[{r2, i}]) ^ ((rows[r2] ^ rooks[{r2, i}]) ^ rooks[{r2, c2}])) == 0) --total;
        }
        for (int i = 0; i < n; ++i) {
            if (i == r2) continue;
            if (((columns[c2] ^ rooks[{i, c2}]) ^ (rows[i] ^ rooks[{i, c2}])) == 0 && ((columns[c2] ^ rooks[{i, c2}] ^ rooks[{r2, c2}]) ^ (rows[i] ^ rooks[{i, c2}])) > 0) ++total;
            else if (((columns[c2] ^ rooks[{i, c2}]) ^ (rows[i] ^ rooks[{i, c2}])) > 0 && ((columns[c2] ^ rooks[{i, c2}] ^ rooks[{r2, c2}]) ^ (rows[i] ^ rooks[{i, c2}])) == 0) --total;
        }
        rows[r2] ^= rooks[{r2, c2}];
        columns[c2] ^= rooks[{r2, c2}];

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

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 3676 KB Output is correct
2 Correct 14 ms 3932 KB Output is correct
3 Correct 10 ms 3676 KB Output is correct
4 Correct 11 ms 3676 KB Output is correct
5 Correct 14 ms 3928 KB Output is correct
6 Runtime error 169 ms 65536 KB Execution killed with signal 9
7 Runtime error 190 ms 65536 KB Execution killed with signal 9
8 Runtime error 176 ms 65536 KB Execution killed with signal 9
9 Runtime error 211 ms 65536 KB Execution killed with signal 9
10 Runtime error 195 ms 65536 KB Execution killed with signal 9
11 Runtime error 323 ms 65536 KB Execution killed with signal 9
12 Runtime error 407 ms 65536 KB Execution killed with signal 9
13 Runtime error 330 ms 65536 KB Execution killed with signal 9
14 Runtime error 341 ms 65536 KB Execution killed with signal 9
15 Runtime error 344 ms 65536 KB Execution killed with signal 9
16 Runtime error 355 ms 65536 KB Execution killed with signal 9
17 Runtime error 357 ms 65536 KB Execution killed with signal 9
18 Runtime error 326 ms 65536 KB Execution killed with signal 9
19 Runtime error 323 ms 65536 KB Execution killed with signal 9
20 Runtime error 330 ms 65536 KB Execution killed with signal 9