Submission #82819

#TimeUsernameProblemLanguageResultExecution timeMemory
82819xiaowuc1Topovi (COCI15_topovi)C++14
120 / 120
1355 ms42800 KiB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

map<int, int> rowXOR;
map<int, int> colXOR;
map<int, int> rowF, colF;
map<pii, int> loc;

void change(map<int, int>& m, int k, int v) {
	m[k] += v;
	if(m[k] == 0) m.erase(k);
}

ll ret;

void flip(int x, int y, int v) {
	ret += colF[rowXOR[x]];
	change(rowF, rowXOR[x], -1);
	rowXOR[x] ^= v;
	change(rowF, rowXOR[x], 1);
	ret -= colF[rowXOR[x]];
	if(rowXOR[x] == 0) rowXOR.erase(x);

	ret += rowF[colXOR[y]];
	change(colF, colXOR[y], -1);
	colXOR[y] ^= v;
	change(colF, colXOR[y], 1);
	ret -= rowF[colXOR[y]];
	if(colXOR[y] == 0) colXOR.erase(y);
}


int main() {
	int n, k, p;
	scanf("%d%d%d", &n, &k, &p);
	rowF[0] = n;
	colF[0] = n;
	while(k--) {
		int x, y, v;
		scanf("%d%d%d", &x, &y, &v);
		loc[{x, y}] = v;
		flip(x, y, v);
	}
	while(p--) {
		int xa, ya, xb, yb;
		scanf("%d%d%d%d", &xa, &ya, &xb, &yb);
		int v = loc[{xa, ya}];
		flip(xa, ya, v);
		flip(xb, yb, v);
		loc.erase({xa, ya});
		loc[{xb, yb}] = v;
		printf("%lld\n", ret);
	}
}

Compilation message (stderr)

topovi.cpp: In function 'int main()':
topovi.cpp:39:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d%d", &n, &k, &p);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~
topovi.cpp:44:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d%d", &x, &y, &v);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~
topovi.cpp:50:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d%d%d", &xa, &ya, &xb, &yb);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...