Submission #650126

# Submission time Handle Problem Language Result Execution time Memory
650126 2022-10-12T13:58:55 Z dozer Topovi (COCI15_topovi) C++14
120 / 120
1018 ms 48204 KB
#include <bits/stdc++.h>
using namespace std;
#define fileio() freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
#define fastio() cin.tie(0), ios_base::sync_with_stdio(0)
#define pb push_back
#define sp " "
#define endl "\n"
#define pii pair<int, int>
#define st first
#define nd second
#define N 1000005
#define int long long

int r[N], c[N], x[N];
map<int, int> cntr, cntc, valr, valc;
map<pii, int> pw;

int32_t main()
{
	fastio();

	int n, k, p;
	cin>>n>>k>>p;
	cntr[0] = n, cntc[0] = n;
	for (int i = 1; i <= k; i++)
	{
		cin>>r[i]>>c[i]>>x[i];
		cntr[valr[r[i]]]--;
		valr[r[i]] ^= x[i];
		cntr[valr[r[i]]]++;
		cntc[valc[c[i]]]--;
		valc[c[i]] ^= x[i];
		cntc[valc[c[i]]]++;
		pw[{r[i], c[i]}] = x[i];
	}
	int ans = n * n;
	for (auto i : cntr) ans -= i.nd * cntc[i.st];
	while(p--)
	{
		int r[3], c[3];
		cin>>r[1]>>c[1]>>r[2]>>c[2];
		int xx = pw[{r[1], c[1]}];
		pw[{r[1], c[1]}] = 0;
		pw[{r[2], c[2]}] = xx;
		for (int i = 1; i <= 2; i++)
		{
			ans += cntc[valr[r[i]]];
			cntr[valr[r[i]]]--;
			ans += cntr[valc[c[i]]];
			cntc[valc[c[i]]]--;
			valr[r[i]] ^= xx;
			cntr[valr[r[i]]]++;
			ans -= cntc[valr[r[i]]];
			valc[c[i]] ^= xx;
			cntc[valc[c[i]]]++;
			ans -= cntr[valc[c[i]]];
		}
		cout<<ans<<endl;
	}

	cerr<<"time taken : "<<(float)clock() / CLOCKS_PER_SEC<<" seconds\n";
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 328 KB Output is correct
2 Correct 1 ms 324 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 101 ms 7248 KB Output is correct
7 Correct 74 ms 6560 KB Output is correct
8 Correct 60 ms 5348 KB Output is correct
9 Correct 60 ms 5520 KB Output is correct
10 Correct 72 ms 5708 KB Output is correct
11 Correct 1006 ms 48128 KB Output is correct
12 Correct 971 ms 48204 KB Output is correct
13 Correct 947 ms 48036 KB Output is correct
14 Correct 955 ms 48084 KB Output is correct
15 Correct 966 ms 48156 KB Output is correct
16 Correct 1018 ms 48144 KB Output is correct
17 Correct 994 ms 48152 KB Output is correct
18 Correct 986 ms 48064 KB Output is correct
19 Correct 1018 ms 48144 KB Output is correct
20 Correct 955 ms 48172 KB Output is correct