답안 #43204

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
43204 2018-03-10T14:54:17 Z baactree 즐거운 사진 수집 (JOI13_collecting) C++14
100 / 100
1435 ms 44676 KB
#include <bits/stdc++.h>
using namespace std;
namespace fio {
	const int BSIZE = 1 << 17;
	unsigned char buffer[BSIZE];
	unsigned char *p = buffer + BSIZE;
	inline unsigned char readChar() {
		if (p == buffer + BSIZE) {
			fread(buffer, 1, 1 << 17, stdin);
			p = buffer;
		}
		return *p++;
	}
	int readInt() {
		unsigned char c = readChar();
		while (c<'-')c = readChar();
		int ret = 0;
		do {
			ret = ret * 10 + c - '0';
			c = readChar();
		} while (c >= '-');
		return ret;
	}
	char outbuf[30];
	
	void print(long long t){
		char *z = outbuf + 29;
		*z-- = '\n';
		do{
			*z-- = t % 10 + '0';
			t /= 10;
		} while (t);
		fwrite(z + 1, 1, outbuf + 29 - z, stdout);
	}
}
int n, q;
int r[21], c[21];
int ro[1 << 20], co[1 << 20];
int rs[21][1 << 20], cs[21][1 << 20];
int main() {
	//scanf("%d%d", &n, &q);
	n = fio::readInt();
	q = fio::readInt();
	long long cnt = 0;
	for (int i = 1; i <= n; i++) 
		r[i] = c[i] = 1 << (n - i);
	while (q--) {
		int a, b;
		//scanf("%d%d", &a, &b);
		a = fio::readInt();
		b = fio::readInt();
		b--;
		if (a) {
			//col
			for (int i = 1, d = 2; i <= n; i++, d <<= 1) {
				int pre = cs[i][b / d];
				int now = co[b] ? pre - 1 : pre + 1;
				cs[i][b / d] = now;
				int k = 0;
				if (!(pre%d))c[i]--, k = 1;
				if (!(now%d))c[i]++, k = -1;
				cnt += r[i] * k;
			}
			co[b] ^= 1;
		}
		else {
			//row
			for (int i = 1, d = 2; i <= n; i++, d <<= 1) {
				int pre = rs[i][b / d];
				int now = ro[b] ? pre - 1 : pre + 1;
				rs[i][b / d] = now;
				int k = 0;
				if (!(pre%d))r[i]--, k = 1;
				if (!(now%d))r[i]++, k = -1;
				cnt += c[i] * k;
			}
			ro[b] ^= 1;
		}
		fio::print(cnt * 4 + 1);
	}
	return 0;
}

Compilation message

collecting.cpp: In function 'unsigned char fio::readChar()':
collecting.cpp:9:36: warning: ignoring return value of 'size_t fread(void*, size_t, size_t, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
    fread(buffer, 1, 1 << 17, stdin);
                                    ^
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 480 KB Output is correct
3 Correct 2 ms 552 KB Output is correct
4 Correct 2 ms 624 KB Output is correct
5 Correct 2 ms 624 KB Output is correct
6 Correct 2 ms 624 KB Output is correct
7 Correct 2 ms 660 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 676 KB Output is correct
2 Correct 3 ms 676 KB Output is correct
3 Correct 2 ms 692 KB Output is correct
4 Correct 2 ms 708 KB Output is correct
5 Correct 2 ms 852 KB Output is correct
6 Correct 3 ms 852 KB Output is correct
7 Correct 3 ms 852 KB Output is correct
8 Correct 2 ms 852 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1435 ms 44256 KB Output is correct
2 Correct 1383 ms 44268 KB Output is correct
3 Correct 1126 ms 44268 KB Output is correct
4 Correct 1313 ms 44676 KB Output is correct
5 Correct 1348 ms 44676 KB Output is correct
6 Correct 1361 ms 44676 KB Output is correct
7 Correct 1383 ms 44676 KB Output is correct
8 Correct 1352 ms 44676 KB Output is correct
9 Correct 1080 ms 44676 KB Output is correct
10 Correct 1207 ms 44676 KB Output is correct
11 Correct 1285 ms 44676 KB Output is correct
12 Correct 1304 ms 44676 KB Output is correct
13 Correct 1124 ms 44676 KB Output is correct