답안 #142621

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
142621 2019-08-10T04:29:33 Z gs18103 즐거운 사진 수집 (JOI13_collecting) C++14
0 / 100
1511 ms 77980 KB
#include <bits/stdc++.h>
#define fastio ios::sync_with_stdio(false); cin.tie(0)
#define all(v) (v).begin(), (v).end()
#define eb emplace_back
#define fi first
#define se second
#define INF 2000000000
#define LINF 1000000000000000000LL

using namespace std;
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

void update(auto &tree, auto &cnt, int x, int n) {
	x += (1 << n) - 1;
	tree[x] = (tree[x] + 1) % 2;
	for(int i = n - 1; i >= 0; i--) {
		x >>= 1;
		if(tree[x*2] ^ tree[x*2+1]) {
			if(tree[x] == 0) cnt[i]++;
			tree[x] = 1;
		}
		else {
			if(tree[x] == 1) cnt[i]--;
			tree[x] = 0;
		}
	}
}

int main() {
	fastio;
	vector <ll> treex, treey, cntx, cnty;
	int n, q;
	cin >> n >> q;
	treex.resize((1<<(n+1))+10);
	treey.resize((1<<(n+1))+10);
	cntx.resize(n+10);
	cnty.resize(n+10);

	while(q--) {
		int t, x;
		cin >> t >> x;
		if(t) update(treex, cntx, x, n);
		else update(treey, cnty, x, n);
		ll ans = 0;
		for(int i = 0; i < n; i++) {
			ans += 1LL * (1<<i) * (cntx[i] + cnty[i]) - cntx[i] * cnty[i];
		}
		cout << ans * 4 + 1 << '\n';
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 504 KB Output is correct
2 Incorrect 2 ms 376 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 504 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1511 ms 77980 KB Output isn't correct
2 Halted 0 ms 0 KB -