CodeForces 339D

#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
using namespace std;
typedef long long LL;
const int maxn = 20;
int a[1<<maxn];
int n, m, u, v;

void Build() {
	int p = 1 << n, res = 0;
	while(p) {
		p >>= 1;
		for(int i = p; i < 2*p; ++i) {
			if(res&1) a[i] = a[i<<1] ^ a[(i<<1)+1];
			else a[i] = a[i<<1] | a[(i<<1)+1];
		}
		res++;
	}
}

void Update(int p) {
	int res = 0;
	while(p) {
		p >>= 1;
		if(res&1) a[p] = a[p<<1] ^ a[(p<<1)+1];
		else a[p] = a[p<<1] | a[(p<<1)+1];
		res++;
	}
}

int main() {
	scanf("%d%d", &n, &m);
	int len = 1 << n, p = len;
	for(int i = 0; i < len; ++i) scanf("%d", &a[len+i]);
	Build();
	while(m--) {
		int u, v; scanf("%d%d", &u, &v);
		a[p+u-1] = v;
		Update(p+u-1);
		printf("%d\n", a[1]);
	}
	return 0;
}

發佈了29 篇原創文章 · 獲贊 3 · 訪問量 1萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章