Submission #648717

# Submission time Handle Problem Language Result Execution time Memory
648717 2022-10-07T17:42:00 Z Adominator Topovi (COCI15_topovi) C++17
120 / 120
1323 ms 33956 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

#define ar array
#define vo vector
#define pb push_back
#define all(x) begin(x), end(x)
#define sz(x) (ll)(x).size()

#define rep(i, a, b) for(ll i=(a); i<(b); i++)
#define repd(i, a, b) for(ll i=(a); i>=(b); i--)

map<int, int> rcnt, ccnt, col, row;
map<ar<int, 2>, int> val;
int n, k, p;
ll ans;

void move(int r, int c, int x) {
    ans-=n-rcnt[col[c]];
    ans-=n-ccnt[row[r]];
    if(col[c]^row[r]) ans++;

    --rcnt[row[r]];
    row[r]^=x;
    ++rcnt[row[r]];

    --ccnt[col[c]];
    col[c]^=x;
    ++ccnt[col[c]];

    ans+=n-rcnt[col[c]];
    ans+=n-ccnt[row[r]];
    if(col[c]^row[r]) ans--;

    val[{r, c}]^=x;
}

int main() {
    cin.tie(0)->sync_with_stdio(0);

    cin >> n >> k >> p;

    ccnt[0]=rcnt[0]=n;

    rep(i, 0, k) {
        int r, c, x;
        cin >> r >> c >> x;

        move(r, c, x);
    }

    rep(i, 0, p) {
        int r1, c1, r2, c2;
        cin >> r1 >> c1 >> r2 >> c2;

        int tmp=val[{r1, c1}];
        move(r1, c1, tmp);
        move(r2, c2, tmp);

        cout << ans << '\n';
    }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 320 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 127 ms 5592 KB Output is correct
7 Correct 126 ms 5088 KB Output is correct
8 Correct 89 ms 4300 KB Output is correct
9 Correct 78 ms 4408 KB Output is correct
10 Correct 89 ms 4460 KB Output is correct
11 Correct 1323 ms 33868 KB Output is correct
12 Correct 1212 ms 33752 KB Output is correct
13 Correct 1071 ms 33832 KB Output is correct
14 Correct 1060 ms 33956 KB Output is correct
15 Correct 1086 ms 33860 KB Output is correct
16 Correct 1071 ms 33848 KB Output is correct
17 Correct 1057 ms 33892 KB Output is correct
18 Correct 1083 ms 33720 KB Output is correct
19 Correct 1152 ms 33812 KB Output is correct
20 Correct 1104 ms 33860 KB Output is correct