답안 #82819

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
82819 2018-11-01T20:45:06 Z xiaowuc1 Topovi (COCI15_topovi) C++14
120 / 120
1355 ms 42800 KB
#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

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);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 456 KB Output is correct
4 Correct 2 ms 480 KB Output is correct
5 Correct 2 ms 484 KB Output is correct
6 Correct 148 ms 3060 KB Output is correct
7 Correct 127 ms 4316 KB Output is correct
8 Correct 96 ms 4316 KB Output is correct
9 Correct 98 ms 4884 KB Output is correct
10 Correct 110 ms 5184 KB Output is correct
11 Correct 1340 ms 26952 KB Output is correct
12 Correct 1355 ms 32812 KB Output is correct
13 Correct 1337 ms 38928 KB Output is correct
14 Correct 1316 ms 42544 KB Output is correct
15 Correct 1317 ms 42644 KB Output is correct
16 Correct 1334 ms 42644 KB Output is correct
17 Correct 1316 ms 42656 KB Output is correct
18 Correct 1343 ms 42688 KB Output is correct
19 Correct 1322 ms 42688 KB Output is correct
20 Correct 1324 ms 42800 KB Output is correct