제출 #743796

#제출 시각아이디문제언어결과실행 시간메모리
743796JellyTheOctopusTopovi (COCI15_topovi)C++17
120 / 120
1536 ms39496 KiB
#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 timeMemoryGrader output
Fetching results...