Submission #98695

#TimeUsernameProblemLanguageResultExecution timeMemory
98695Dat160601Topovi (COCI15_topovi)C++17
120 / 120
1397 ms33600 KiB
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define fi first
#define se second

long long n, ans;
int k, p, r, c, x;
map <int, int> cnt[2], val[2];
map < pair <int, int>, int > a;

void update(int tp, int pos, int v){
	int cur = val[tp][pos];
	ans += 1LL * cnt[0][cur] * cnt[1][cur];
	cnt[tp][cur]--;
	ans -= 1LL * cnt[0][cur] * cnt[1][cur];
	cur ^= v;
	val[tp][pos] = cur;
	ans += 1LL * cnt[0][cur] * cnt[1][cur];
	cnt[tp][cur]++;
	ans -= 1LL * cnt[0][cur] * cnt[1][cur];
}

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin >> n >> k >> p;
	cnt[0][0] = cnt[1][0] = n;
	while(k --){
		cin >> r >> c >> x;
		a[mp(r, c)] = x;
		update(0, r, x), update(1, c, x);
	}
	while(p --){
		int ar, ac;
		cin >> r >> c >> ar >> ac;
		x = a[mp(r, c)];
		a[mp(r, c)] = 0, a[mp(ar, ac)] = x;
		update(0, r, x), update(1, c, x);
		update(0, ar, x), update(1, ac, x);
		cout << ans << "\n";
	}
}
#Verdict Execution timeMemoryGrader output
Fetching results...