답안 #787321

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
787321 2023-07-19T05:11:29 Z 박상훈(#10032) 즐거운 사진 수집 (JOI13_collecting) C++17
0 / 100
644 ms 14448 KB
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
int cntR[21][2], cntC[21][2], onR[1<<21], onC[1<<21], R[21][1<<21], C[21][1<<21];

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n, q;
	cin >> n >> q;

	ll ans = 1;
	for (int i=1;i<=n;i++){
		cntR[i][0] = 1<<(n-i);
		cntC[i][0] = 1<<(n-i);
	}

	// int sz = 1<<n;

	while(q--){
		int op, x;
		scanf("%d %d", &op, &x);
		--x;

		if (op==0){
			onR[x] ^= 1;
			for (int i=1;i<=n;i++){
				int &cnt = R[i][x>>i];
				if (cnt==0){
					ans += (4LL) * cntC[i][0];
					cntR[i][0]--;
				} 
				else if (cnt==(1<<i)){
					ans += (4LL) * cntC[i][1];
					cntR[i][1]--;
				} 
				// printf("add %lld\n", (1LL<<(i*2)) * cntC[i][msk]);
				// cntR[i][msk]--;

				if (onR[x]==1) cnt++;
				else cnt--;

				if (cnt==0){
					ans -= (4LL) * cntC[i][0];
					cntR[i][0]++;
				} 
				else if (cnt==(1<<i)){
					ans -= (4LL) * cntC[i][1];
					cntR[i][1]++;
				} 
			}
		}

		else{
			onC[x] ^= 1;

			for (int i=1;i<=n;i++){
				int &cnt = C[i][x>>i];
				if (cnt==0){
					ans += (4LL) * cntR[i][0];
					cntC[i][0]--;
				} 
				else if (cnt==(1<<i)){
					ans += (4LL) * cntR[i][1];
					cntC[i][1]--;
				} 
				// printf("add %lld\n", (1LL<<(i*2)) * cntC[i][msk]);
				// cntR[i][msk]--;

				if (onC[x]==1) cnt++;
				else cnt--;

				if (cnt==0){
					ans -= (4LL) * cntR[i][0];
					cntC[i][0]++;
				} 
				else if (cnt==(1<<i)){
					ans -= (4LL) * cntR[i][1];
					cntC[i][1]++;
				} 
			}
		}

		printf("%lld\n", ans);
	}
}

Compilation message

collecting.cpp: In function 'int main()':
collecting.cpp:23:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |   scanf("%d %d", &op, &x);
      |   ~~~~~^~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 328 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 644 ms 14448 KB Output isn't correct
2 Halted 0 ms 0 KB -