답안 #43194

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
43194 2018-03-10T14:14:52 Z baactree 즐거운 사진 수집 (JOI13_collecting) C++14
30 / 100
5000 ms 54568 KB
#include <bits/stdc++.h>
using namespace std;
int n, q;
int r[21][1 << 20], c[21][1 << 20];
int rs[1 << 21], cs[1 << 21];
int ro[1 << 20], co[1 << 20];
int sz = 1 << 20;
int pre[21];
void update(int idx, int val, int *tree) {
	idx += sz;
	while (idx) {
		tree[idx] += val;
		idx /= 2;
	}
}
int query(int le, int ri, int *tree) {
	int ret = 0;
	le += sz;
	ri += sz;
	while (le <= ri) {
		if (le & 1)ret += tree[le++];
		if (!(ri & 1))ret += tree[ri--];
		le /= 2;
		ri /= 2;
	}
	return ret;
}
int main() {
	scanf("%d%d", &n, &q);
	long long cnt = 0;
	for (int i = 1; i <= n; i++)
		r[i][0] = c[i][0] = 1 << (n - i);
	while (q--) {
		int a, b;
		scanf("%d%d", &a, &b);
		b--;
		if (a) {
			//col
			for (int i = 1, d = 2; i <= n; i++, d <<= 1) {
				pre[i] = query(b / d*d, (b / d + 1)*d - 1,cs) % d;
				c[i][pre[i]]--;
			}
			update(b, co[b] ? -1 : 1, cs);
			co[b] ^= 1;
			for (int i = 1, d = 2; i <= n; i++,d<<=1) {
				int now = query(b / d*d, (b / d + 1)*d - 1, cs) % d;
				c[i][now]++;
				long long k = 0;
				if (pre[i] == 0)k = 1;
				else if (now == 0)k = -1;
				cnt += r[i][0] * k;
			}
		}
		else {
			//row
			for (int i = 1, d = 2; i <= n; i++, d <<= 1) {
				pre[i] = query(b / d*d, (b / d + 1)*d - 1, rs) % d;
				r[i][pre[i]]--;
			}
			update(b, ro[b] ? -1 : 1, rs);
			ro[b] ^= 1;
			for (int i = 1, d = 2; i <= n; i++, d <<= 1) {
				int now = query(b / d*d, (b / d + 1)*d - 1, rs) % d;
				r[i][now]++;
				long long k = 0;
				if (pre[i] == 0)k = 1;
				else if (now == 0)k = -1;
				cnt += c[i][0] * k;
			}
		}
		printf("%lld\n", cnt * 4 + 1);
	}
	return 0;
}

Compilation message

collecting.cpp: In function 'int main()':
collecting.cpp:29:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &n, &q);
                       ^
collecting.cpp:35:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d", &a, &b);
                        ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 376 KB Output is correct
2 Correct 2 ms 608 KB Output is correct
3 Correct 2 ms 680 KB Output is correct
4 Correct 2 ms 752 KB Output is correct
5 Correct 2 ms 752 KB Output is correct
6 Correct 2 ms 752 KB Output is correct
7 Correct 2 ms 824 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 860 KB Output is correct
2 Correct 4 ms 860 KB Output is correct
3 Correct 4 ms 876 KB Output is correct
4 Correct 4 ms 892 KB Output is correct
5 Correct 4 ms 908 KB Output is correct
6 Correct 4 ms 908 KB Output is correct
7 Correct 4 ms 924 KB Output is correct
8 Correct 4 ms 928 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 5023 ms 54568 KB Time limit exceeded
2 Halted 0 ms 0 KB -