# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
87926 | Good | Topovi (COCI15_topovi) | C++11 | 1814 ms | 64096 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/*
ID: blackha5
TASK: test
LANG: C++
*/
#include <bits/stdc++.h>
#define ff first
#define ss second
#define Maxn 100003
#define ll long long
#define pb push_back
#define Inf 1000000009
#define ppb() pop_back()
#define pii pair <int , int>
#define mid(x, y) (x + y) / 2
#define all(x) x.begin(),x.end()
#define llInf 1000000000000000009
#define tr(i, c) for(__typeof(c).begin() i = (c).begin() ; i != (c).end() ; i++)
using namespace std;
ll ans;
int n, k, p;
map <pii, int> E;
map <int, int> R, C;
map <int, int> cntr, cntc;
int main () {
//freopen ("file.in", "r", stdin);
//freopen ("file.out", "w", stdout);
//srand ((unsigned) time ( NULL ));
//int randomNumber = rand() % 10 + 1;
scanf ("%d%d%d", &n, &k, &p);
cntr[0] = n, cntc[0] = n;
for (int i = 1; i <= k; i++) {
int r, c, x;
scanf ("%d%d%d", &r, &c, &x);
E[{r, c}] = x;
cntr[R[r]] --, cntc[C[c]] --;
R[r] ^= x, C[c] ^= x;
cntr[R[r]] ++, cntc[C[c]] ++;
}
for (auto i: cntr)
ans += 1ll * (n - cntc[i.ff]) * i.ss;
while (p--) {
int r1, c1;
int r2, c2;
scanf ("%d%d%d%d", &r1, &c1, &r2, &c2);
int x = E[{r1, c1}];
E[{r1, c1}] = 0;
E[{r2, c2}] = x;
ans -= n - cntc[R[r1]];
ans -= n - cntr[C[c1]];
if (R[r1] != C[c1])
ans ++;
cntr[R[r1]] --, cntc[C[c1]] --;
R[r1] ^= x, C[c1] ^= x;
cntr[R[r1]] ++, cntc[C[c1]] ++;
ans += n - cntc[R[r1]];
ans += n - cntr[C[c1]];
if (R[r1] != C[c1])
ans --;
ans -= n - cntc[R[r2]];
ans -= n - cntr[C[c2]];
if (R[r2] != C[c2])
ans ++;
cntr[R[r2]] --, cntc[C[c2]] --;
R[r2] ^= x, C[c2] ^= x;
cntr[R[r2]] ++, cntc[C[c2]] ++;
ans += n - cntc[R[r2]];
ans += n - cntr[C[c2]];
if (R[r2] != C[c2])
ans --;
printf ("%lld\n", ans);
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |