Submission #743796

# Submission time Handle Problem Language Result Execution time Memory
743796 2023-05-18T03:00:09 Z JellyTheOctopus Topovi (COCI15_topovi) C++17
120 / 120
1536 ms 39496 KB
#include <bits/stdc++.h>
using namespace std;

int N, K, P;
long long ans = 0;
map<int, int> rowCnt, colCnt;
map<int, int> rowXOR, colXOR;
map<pair<int, int>, int> rook;

void move(int r, int c, int val) {
	ans -= (N-colCnt[rowXOR[r]]);
	ans -= (N-rowCnt[colXOR[c]]);
	if (rowXOR[r] != colXOR[c]) {
		ans++;
	}

	rowCnt[rowXOR[r]]--;
	rowXOR[r] ^= val;
	rowCnt[rowXOR[r]]++;

	colCnt[colXOR[c]]--;
	colXOR[c] ^= val;
	colCnt[colXOR[c]]++;

	ans += (N-colCnt[rowXOR[r]]);
	ans += (N-rowCnt[colXOR[c]]);

	if (rowXOR[r] != colXOR[c]){
		ans--;
	}
	rook[{r, c}] ^= val;
}	

int main() {
	cin >> N >> K >> P;
	rowCnt[0] = N;
	colCnt[0] = N;
	while (K--) {
		int r, c, val;
		cin >> r >> c >> val;
		r--;
		c--;
		move(r, c, val);
	}
	while (P--) {
		int r1, c1, r2, c2;
		cin >> r1 >> c1 >> r2 >> c2;
		r1--; c1--; r2--; c2--;
		int rookVal = rook[{r1, c1}];
		move(r1, c1, rookVal);
		move(r2, c2, rookVal);
		cout << ans << "\n";
	}
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 300 KB Output is correct
4 Correct 1 ms 300 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 182 ms 5948 KB Output is correct
7 Correct 135 ms 5256 KB Output is correct
8 Correct 109 ms 4344 KB Output is correct
9 Correct 104 ms 4428 KB Output is correct
10 Correct 129 ms 4680 KB Output is correct
11 Correct 1536 ms 39464 KB Output is correct
12 Correct 1513 ms 39400 KB Output is correct
13 Correct 1496 ms 39496 KB Output is correct
14 Correct 1430 ms 39348 KB Output is correct
15 Correct 1463 ms 39400 KB Output is correct
16 Correct 1442 ms 39432 KB Output is correct
17 Correct 1517 ms 39376 KB Output is correct
18 Correct 1454 ms 39336 KB Output is correct
19 Correct 1447 ms 39300 KB Output is correct
20 Correct 1417 ms 39472 KB Output is correct