Submission #98695

# Submission time Handle Problem Language Result Execution time Memory
98695 2019-02-25T04:53:15 Z Dat160601 Topovi (COCI15_topovi) C++17
120 / 120
1397 ms 33600 KB
#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 time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 3 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 140 ms 5356 KB Output is correct
7 Correct 130 ms 4820 KB Output is correct
8 Correct 86 ms 3996 KB Output is correct
9 Correct 88 ms 3996 KB Output is correct
10 Correct 97 ms 4268 KB Output is correct
11 Correct 1347 ms 33576 KB Output is correct
12 Correct 1249 ms 33484 KB Output is correct
13 Correct 1316 ms 33524 KB Output is correct
14 Correct 1235 ms 33444 KB Output is correct
15 Correct 1397 ms 33492 KB Output is correct
16 Correct 1282 ms 33548 KB Output is correct
17 Correct 1397 ms 33428 KB Output is correct
18 Correct 1366 ms 33540 KB Output is correct
19 Correct 1371 ms 33600 KB Output is correct
20 Correct 1343 ms 33516 KB Output is correct