#include <bits/stdc++.h>

using namespace std;
#define int long long
const int MAXN = 100100, MAXR = 320;

int n, m, ans, lb, v[MAXN];
bool on[MAXN][20], okk;

int g(int x, int bit){
	if(x % 2 == 0)
		return (x / 2ll) * (x + 1ll) * (1ll << bit);
	return ((x + 1ll) / 2ll) * x * (1ll << bit);
}

struct block{
	bool f, a[MAXR];
	int l, r, id, bit, sz;

	block(int l, int r, int bit, int aux) : l(l), r(r), bit(bit), id(aux), f(0) {
		// cout << "Criando o block " << aux << " " << bit << " {l, r} = " << l << " " << r << "\n";
		for(int i = l, pos = 0;i <= r;i++, pos++){
			a[pos] = on[i][bit], f = max(f, on[i][bit]), sz = pos;
			// dbg(a[pos], pos);
		}
		sz++;
		// dbg(sz);
	}

	block(){};
} b[MAXR][20];

void update(int pos, int x, int id, int bit, int sz){
	if(b[id][bit].a[pos] == x)
		return;

	/*dbg(pos, x, id, bit, sz);
	for(int i = 0;i < b[id][bit].sz;i++)
		cout << b[id][bit].a[i] << " ";
	cout << "\n";*/
	int lz = -1ll, rz = n;
	for(int i = pos - 1ll;i >= 0;i--)
		if(b[id][bit].a[i] == 0){
			lz = MAXR * id + i;
			break;
		}
	if(lz == -1ll && id != 0){
		int aux = id - 1ll;
		while(aux >= 0 && b[aux][bit].f == 0ll)
			aux--;
		if(aux == -1ll)
			lz = -1ll;
		else for(int i = b[aux][bit].sz - 1ll;i >= 0;i--)
			if(b[aux][bit].a[i] == 0){
				lz = MAXR * aux + i;
				break;
			}
	}

	for(int i = pos + 1ll;i < sz;i++)
		if(b[id][bit].a[i] == 0){
			rz = MAXR * id + i;
			break;
		}
	if(rz == n && id != lb){
		int aux = id + 1ll;
		while(aux <= lb && b[aux][bit].f == 0ll)
			aux++;
		if(aux > lb)
			rz = n;
		else for(int i = 0;i < sz;i++)
			if(b[aux][bit].a[i] == 0){
				rz = MAXR * aux + i;
				break;
			}
	}

	b[id][bit].a[pos] = !b[id][bit].a[pos];
	if(b[id][bit].a[pos] == 1ll){
		pos = MAXR * id + pos;
		// dbg(lz, rz, pos, bit);
		ans -= g(pos - lz - 1ll, bit) + g(rz - pos - 1ll, bit);
		// if(okk) cout << "S: " << g(pos - lz - 1ll, bit) + g(rz - pos - 1ll, bit) << "\n" << "ans = " << ans << "\n";
		ans += g(rz - lz - 1ll, bit);
		// if(okk) cout << "So: " << g(rz - lz - 1ll, bit) << "\n" << "ans = " << ans << "\n";
		// dbg(ans);
	} else {
		pos = MAXR * id + pos;
		// dbg(lz, rz, pos, bit);
		ans += g(pos - lz - 1ll, bit) + g(rz - pos - 1ll, bit);
		// if(okk) cout << "So: " << g(pos - lz - 1ll, bit) + g(rz - pos - 1ll, bit) << "\n" << "ans = " << ans << "\n";
		ans -= g(rz - lz - 1ll, bit);
		// if(okk) cout << "S: " << g(rz - lz - 1ll, bit) << "\n" << "ans = " << ans << "\n";
		// dbg(ans);
	}
	// if(okk) cout << "ans: " << ans << "\n";
	if(okk) cout << lz << " " << pos << " " << rz << "\n";

	bool ok = 0;
	for(int i = 0;i < b[id][bit].sz;i++)
		if(b[id][bit].a[i] == 0)
			ok = b[id][bit].f = 1ll;
	if(!ok)
		b[id][bit].f = 0;

	// cout << "\n";
}

signed main(){
	scanf("%lld %lld", &n, &m);
	int auxl = 0, auxr = 0, aux = 0;
	lb = (n - 1ll) / MAXR;
	for(int i = 0;i < n;i++, auxr++){
		scanf("%lld", &v[i]);
		// dbg(bitset<1ll0>(v[i]));
		for(int j = 0;j < 20;j++)
			on[i][j] = ((v[i] >> j) & 1ll);
		if((i % MAXR == 0 && i != 0) || i == n - 1ll){
			for(int j = 0;j < 20;j++)
				b[aux][j] = block(auxl, auxr - (i != n - 1ll), j, aux);
			aux++;
			auxl = i;
		}
	}

	for(int j = 0;j < 20;j++){
		vector<int> k;
		for(int i = 0;i < n;i++){
			if(((v[i] >> j) & 1ll) && (i == 0 || !((v[i - 1ll] >> j) & 1ll)))
				k.push_back(i);
			if(((v[i] >> j) & 1ll) && (i == n - 1ll || !((v[i + 1ll] >> j) & 1ll)))
				k.push_back(i);
		}
		// dbg(k);
		if(k.size() == 0) continue;
		for(int i = 0;i < k.size();i += 2)
			ans += g(k[i + 1ll] - k[i] + 1ll, j);

	}

	// if(n == 1e5 && m == 1e5 && v[0] == 1e5) cout << "ans = //" << ans << "\n";
	okk = (n == 1e5 && m == 1e5 && v[0] == 1e5);

	while(m--){
		int p, x;
		scanf("%lld %lld", &p, &x), p--;

		for(int i = 0;i < 20;i++){
			update(p % MAXR, (x >> i) & 1ll, p/MAXR, i, b[p/MAXR][i].sz);
		}

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


#include <bits/stdc++.h>

using namespace std;
const int MAXN = 100100, MAXR = 320;

#define int long long
int n, m, ans, v[MAXN];
bool on[MAXN][20];

int g(int x, int bit){
	return ((x * (x + 1)) / 2) * (1 << bit);
}

struct block{
	bool f, a[MAXR];
	int l, r, id, bit, sz;

	block(int l, int r, int bit, int aux) : l(l), r(r), bit(bit), id(aux), f(0) {
		// cout << "Criando o block " << aux << " " << bit << " {l, r} = " << l << " " << r << "\n";
		for(int i = l, pos = 0;i <= r;i++, pos++){
			a[pos] = on[i][bit], f = max(f, on[i][bit]), sz = pos;
			// dbg(a[pos], pos);
		}
		sz++;
		// dbg(sz);
	}

	block(){};
} b[MAXR][20];

void update(int pos, int x, int id, int bit, int sz){
	if(b[id][bit].a[pos] == x)
		return;

	/*dbg(pos, x, id, bit, sz);
	for(int i = 0;i < b[id][bit].sz;i++)
		cout << b[id][bit].a[i] << " ";
	cout << "\n";*/
	int lz = -1, rz = -1;
	for(int i = pos - 1;i >= 0;i--)
		if(b[id][bit].a[i] == 0){
			lz = MAXR * id + i;
			break;
		}
	if(lz == -1){
		int aux = id - 1;
		while(aux > 0 && b[aux][bit].f == 1)
			aux--;
		if(aux == -1)
			lz = -1;
		else for(int i = MAXR - 1;i >= 0;i--)
			if(b[aux][bit].a[i] == 0){
				lz = MAXR * aux + i;
				break;
			}
	}

	for(int i = pos + 1;i < sz;i++)
		if(b[id][bit].a[i] == 0){
			rz = MAXR * id + i;
			break;
		}
	if(rz == -1){
		int aux = id + 1;
		while(aux <= (n-1) / MAXR && b[aux][bit].f == 1)
			aux++;
		// dbg(aux);
		if(aux >= (n-1) / MAXR)
			rz = n;
		else for(int i = 0;i < sz;i++)
			if(b[aux][bit].a[i] == 0){
				rz = MAXR * aux + i;
				break;
			}
	}

	b[id][bit].a[pos] = !b[id][bit].a[pos];
	if(b[id][bit].a[pos] == 1){
		// dbg(lz, rz, pos, bit);
		ans -= g(pos - lz - 1, bit);
		ans -= g(rz - pos - 1, bit);
		ans += g(rz - lz - 1, bit);
		// dbg(ans);
	} else {
		// dbg(lz, rz, pos, bit);
		ans -= g(rz - lz - 1, bit);
		ans += g(pos - lz - 1, bit);
		ans += g(rz - pos - 1, bit);
		// dbg(ans);
	}

	bool ok = 0;
	for(int i = 0;i < b[id][bit].sz;i++)
		if(b[id][bit].a[i] == 0)
			ok = b[id][bit].f = 1;
	if(!ok)
		b[id][bit].f = 0;

	// cout << "\n";
}

signed main(){
	scanf("%lld %lld", &n, &m);
	int auxl = 0, auxr = 0, aux = 0;
	for(int i = 0;i < n;i++, auxr++){
		scanf("%lld", &v[i]);
		// dbg(bitset<10>(v[i]));
		for(int j = 0;j < 20;j++)
			on[i][j] = ((v[i] >> j) & 1);
		if((i % MAXR == 0 && i != 0) || i == n - 1){
			for(int j = 0;j < 20;j++)
				b[aux][j] = block(auxl, auxr - (i != n - 1), j, aux);
			aux++;
			auxl = i;
		}
	}

	for(int j = 0;j < 20;j++){
		int last = -1;
		for(int i = 0;i < n;i++){
			if(((v[i] >> j) & 1) && (i == 0 || !((v[i - 1] >> j) & 1)))
				last = i;
			if(!((v[i] >> j) & 1) && last != -1)
				ans += g(i - last, j);
		}
		if(last != -1) ans += g(n - last, j);
	}
	// dbg(ans);

	while(m--){
		int p, x;
		scanf("%lld %lld", &p, &x), p--;

		for(int i = 0;i < 20;i++){
			update(p % MAXR, (x >> i) & 1, p/MAXR, i, b[p/MAXR][i].sz);
		}

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


#include <bits/stdc++.h>

using namespace std;
#define int long long
const int MAXN = 100100, MAXR = 320;

int n, m, ans, lb, v[MAXN];
bool on[MAXN][20], okk;

int g(int x, int bit){
	if(x % 2 == 0)
		return (x / 2ll) * (x + 1ll) * (1ll << bit);
	return ((x + 1ll) / 2ll) * x * (1ll << bit);
}

struct block{
	bool f, a[MAXR];
	int l, r, id, bit, sz;

	block(int l, int r, int bit, int aux) : l(l), r(r), bit(bit), id(aux), f(0) {
		// cout << "Criando o block " << aux << " " << bit << " {l, r} = " << l << " " << r << "\n";
		for(int i = l, pos = 0;i <= r;i++, pos++){
			a[pos] = on[i][bit], f = max(f, on[i][bit]), sz = pos;
			// dbg(a[pos], pos);
		}
		sz++;
		// dbg(sz);
	}

	block(){};
} b[MAXR][20];

void update(int pos, int x, int id, int bit, int sz){
	if(b[id][bit].a[pos] == x)
		return;

	/*dbg(pos, x, id, bit, sz);
	for(int i = 0;i < b[id][bit].sz;i++)
		cout << b[id][bit].a[i] << " ";
	cout << "\n";*/
	int lz = -1ll, rz = n;
	for(int i = pos - 1ll;i >= 0;i--)
		if(b[id][bit].a[i] == 0){
			lz = MAXR * id + i;
			break;
		}
	if(lz == -1ll && id != 0){
		int aux = id - 1ll;
		while(aux >= 0 && b[aux][bit].f == 1ll)
			aux--;
		if(aux == -1ll)
			lz = -1ll;
		else for(int i = b[aux][bit].sz - 1ll;i >= 0;i--)
			if(b[aux][bit].a[i] == 0){
				lz = MAXR * aux + i;
				break;
			}
	}

	for(int i = pos + 1ll;i < sz;i++)
		if(b[id][bit].a[i] == 0){
			rz = MAXR * id + i;
			break;
		}
	if(rz == n && id != lb){
		int aux = id + 1ll;
		while(aux <= lb && b[aux][bit].f == 1ll)
			aux++;
		if(aux > lb)
			rz = n;
		else for(int i = 0;i < b[aux][bit].sz;i++)
			if(b[aux][bit].a[i] == 0){
				rz = MAXR * aux + i;
				break;
			}
	}

	b[id][bit].a[pos] = x;
	if(b[id][bit].a[pos] == 1ll){
		pos = MAXR * id + pos;
		// dbg(lz, rz, pos, bit);
		ans -= g(pos - lz - 1ll, bit) + g(rz - pos - 1ll, bit);
		// if(okk) cout << "S: " << g(pos - lz - 1ll, bit) + g(rz - pos - 1ll, bit) << "\n" << "ans = " << ans << "\n";
		ans += g(rz - lz - 1ll, bit);
		// if(okk) cout << "So: " << g(rz - lz - 1ll, bit) << "\n" << "ans = " << ans << "\n";
		// dbg(ans);
	} else {
		pos = MAXR * id + pos;
		// dbg(lz, rz, pos, bit);
		ans += g(pos - lz - 1ll, bit) + g(rz - pos - 1ll, bit);
		// if(okk) cout << "So: " << g(pos - lz - 1ll, bit) + g(rz - pos - 1ll, bit) << "\n" << "ans = " << ans << "\n";
		ans -= g(rz - lz - 1ll, bit);
		// if(okk) cout << "S: " << g(rz - lz - 1ll, bit) << "\n" << "ans = " << ans << "\n";
		// dbg(ans);
	}
	// if(okk) cout << "ans: " << ans << "\n";
	// if(okk) cout << lz << " " << pos << " " << rz << "\n";

	bool ok = 0;
	for(int i = 0;i < sz;i++)
		if(b[id][bit].a[i] == 0)
			ok = b[id][bit].f = 1ll;
	if(!ok)
		b[id][bit].f = 0;

	// cout << "\n";
}

signed main(){
	scanf("%lld %lld", &n, &m);
	int auxl = 0, auxr = 0, aux = 0;
	lb = (n - 1ll) / MAXR;
	for(int i = 0;i < n;i++, auxr++){
		scanf("%lld", &v[i]);
		// dbg(bitset<1ll0>(v[i]));
		for(int j = 0;j < 20;j++)
			on[i][j] = ((v[i] >> j) & 1ll);
		if((i % MAXR == 0 && i != 0) || i == n - 1ll){
			for(int j = 0;j < 20;j++)
				b[aux][j] = block(auxl, auxr - (i != n - 1ll), j, aux);
			aux++;
			auxl = i;
		}
	}

	for(int j = 0;j < 20;j++){
		vector<int> k;
		for(int i = 0;i < n;i++){
			if(((v[i] >> j) & 1ll) && (i == 0 || !((v[i - 1ll] >> j) & 1ll)))
				k.push_back(i);
			if(((v[i] >> j) & 1ll) && (i == n - 1ll || !((v[i + 1ll] >> j) & 1ll)))
				k.push_back(i);
		}
		// dbg(k);
		if(k.size() == 0) continue;
		for(int i = 0;i < k.size();i += 2)
			ans += g(k[i + 1ll] - k[i] + 1ll, j);

	}

	// if(n == 1e5 && m == 1e5 && v[0] == 1e5) cout << "ans = //" << ans << "\n";
	okk = (n == 1e5 && m == 1e5 && v[0] == 1e5);

	while(m--){
		int p, x;
		scanf("%lld %lld", &p, &x), p--;

		for(int i = 0;i < 20;i++){
			update(p % MAXR, (x >> i) & 1ll, p/MAXR, i, b[p/MAXR][i].sz);
		}

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


#include <bits/stdc++.h>

using namespace std;
#define int long long
const int MAXN = 100100, MAXR = 320;

int n, m, ans, lb, v[MAXN];
bool on[MAXN][20];

int g(int x, int bit){
	if(x % 2 == 0)
		return (x / 2ll) * (x + 1ll) * (1ll << bit);
	return ((x + 1ll) / 2ll) * x * (1ll << bit);
}

struct block{
	bool f, a[MAXR];
	int l, r, id, bit, sz;

	block(int l, int r, int bit, int aux) : l(l), r(r), bit(bit), id(aux), f(0) {
		for(int i = l, pos = 0;i <= r;i++, pos++)
			a[pos] = on[i][bit], f = (a[pos] == 0 ? 1 : f), sz = pos;
		sz++;
	}

	block(){};
} b[MAXR][20];

void update(int pos, int x, int id, int bit, int sz){
	if(b[id][bit].a[pos] == x)
		return;

	int lz = -1ll, rz = n;
	for(int i = pos - 1ll;i >= 0;i--)
		if(b[id][bit].a[i] == 0){
			lz = MAXR * id + i;
			break;
		}
	if(lz == -1ll && id != 0){
		int aux = id - 1ll;
		while(aux >= 0 && b[aux][bit].f == 0ll)
			aux--;
		if(aux == -1ll)
			lz = -1ll;
		else for(int i = b[aux][bit].sz - 1ll;i >= 0;i--)
			if(b[aux][bit].a[i] == 0){
				lz = MAXR * aux + i;
				break;
			}
	}

	for(int i = pos + 1ll;i < sz;i++)
		if(b[id][bit].a[i] == 0){
			rz = MAXR * id + i;
			break;
		}
	if(rz == n && id != lb){
		int aux = id + 1ll;
		while(aux <= lb && b[aux][bit].f == 0ll)
			aux++;
		if(aux > lb)
			rz = n;
		else for(int i = 0;i < b[aux][bit].sz;i++)
			if(b[aux][bit].a[i] == 0){
				rz = MAXR * aux + i;
				break;
			}
	}

	b[id][bit].a[pos] = x;
	if(b[id][bit].a[pos] == 1ll){
		pos = MAXR * id + pos;
		ans -= g(pos - lz - 1ll, bit) + g(rz - pos - 1ll, bit);
		ans += g(rz - lz - 1ll, bit);
	} else {
		pos = MAXR * id + pos;
		ans += g(pos - lz - 1ll, bit) + g(rz - pos - 1ll, bit);
		ans -= g(rz - lz - 1ll, bit);
	}

	bool ok = 0;
	for(int i = 0;i < sz;i++)
		if(b[id][bit].a[i] == 0)
			ok = b[id][bit].f = 1ll;
	if(!ok)
		b[id][bit].f = 0;
}

signed main(){
	scanf("%lld %lld", &n, &m);
	int auxl = 0, auxr = 0, aux = 0;
	lb = (n - 1ll) / MAXR;
	for(int i = 0;i < n;i++, auxr++){
		scanf("%lld", &v[i]);
		for(int j = 0;j < 20;j++)
			on[i][j] = ((v[i] >> j) & 1ll);
		if((i % MAXR == 0 && i != 0) || i == n - 1ll){
			for(int j = 0;j < 20;j++)
				b[aux][j] = block(auxl, auxr - (i != n - 1ll), j, aux);
			aux++;
			auxl = i;
		}
	}

	for(int j = 0;j < 20;j++){
		vector<int> k;
		for(int i = 0;i < n;i++){
			if(((v[i] >> j) & 1ll) && (i == 0 || !((v[i - 1ll] >> j) & 1ll)))
				k.push_back(i);
			if(((v[i] >> j) & 1ll) && (i == n - 1ll || !((v[i + 1ll] >> j) & 1ll)))
				k.push_back(i);
		}
		if(k.size() == 0) continue;
		for(int i = 0;i < k.size();i += 2)
			ans += g(k[i + 1ll] - k[i] + 1ll, j);
	}

	while(m--){
		int p, x;
		scanf("%lld %lld", &p, &x), p--;

		for(int i = 0;i < 20;i++)
			update(p % MAXR, (x >> i) & 1ll, p/MAXR, i, b[p/MAXR][i].sz);

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


#include <bits/stdc++.h>

using namespace std;
#define int long long
const int MAXN = 100100, MAXR = 320;

int n, m, ans, lb, v[MAXN];
bool on[MAXN][20];

int g(int x, int bit){
	if(x % 2 == 0)
		return (x / 2ll) * (x + 1ll) * (1ll << bit);
	return ((x + 1ll) / 2ll) * x * (1ll << bit);
}

struct block{
	bool f, a[MAXR];
	int l, r, id, bit, sz;

	block(int l, int r, int bit, int aux) : l(l), r(r), bit(bit), id(aux), f(0) {
		// cout << "Criando o block " << aux << " " << bit << " {l, r} = " << l << " " << r << "\n";
		for(int i = l, pos = 0;i <= r;i++, pos++){
			a[pos] = on[i][bit], f = max(f, on[i][bit]), sz = pos;
			// dbg(a[pos], pos);
		}
		sz++;
		// dbg(sz);
	}

	block(){};
} b[MAXR][20];

void update(int pos, int x, int id, int bit, int sz){
	if(b[id][bit].a[pos] == x)
		return;

	/*dbg(pos, x, id, bit, sz);
	for(int i = 0;i < b[id][bit].sz;i++)
		cout << b[id][bit].a[i] << " ";
	cout << "\n";*/
	int lz = -1ll, rz = n;
	for(int i = pos - 1ll;i >= 0;i--)
		if(b[id][bit].a[i] == 0){
			lz = MAXR * id + i;
			break;
		}
	if(lz == -1ll && id != 0){
		int aux = id - 1ll;
		while(aux >= 0 && b[aux][bit].f == 0ll)
			aux--;
		if(aux == -1ll)
			lz = -1ll;
		else for(int i = b[aux][bit].sz - 1ll;i >= 0;i--)
			if(b[aux][bit].a[i] == 0){
				lz = MAXR * aux + i;
				break;
			}
	}

	for(int i = pos + 1ll;i < sz;i++)
		if(b[id][bit].a[i] == 0){
			rz = MAXR * id + i;
			break;
		}
	if(rz == n && id != lb){
		int aux = id + 1ll;
		while(aux <= lb && b[aux][bit].f == 0ll)
			aux++;
		if(aux > lb)
			rz = n;
		else for(int i = 0;i < sz;i++)
			if(b[aux][bit].a[i] == 0){
				rz = MAXR * aux + i;
				break;
			}
	}

	b[id][bit].a[pos] = !b[id][bit].a[pos];
	if(b[id][bit].a[pos] == 1ll){
		pos = MAXR * id + pos;
		// dbg(lz, rz, pos, bit);
		ans -= g(pos - lz - 1ll, bit) + g(rz - pos - 1ll, bit);
		ans += g(rz - lz - 1ll, bit);
		// dbg(ans);
	} else {
		pos = MAXR * id + pos;
		// dbg(lz, rz, pos, bit);
		ans += g(pos - lz - 1ll, bit) + g(rz - pos - 1ll, bit);
		ans -= g(rz - lz - 1ll, bit);
		// dbg(ans);
	}

	bool ok = 0;
	for(int i = 0;i < b[id][bit].sz;i++)
		if(b[id][bit].a[i] == 0)
			ok = b[id][bit].f = 1ll;
	if(!ok)
		b[id][bit].f = 0;

	// cout << "\n";
}

signed main(){
	scanf("%lld %lld", &n, &m);
	int auxl = 0, auxr = 0, aux = 0;
	lb = (n - 1ll) / MAXR;
	for(int i = 0;i < n;i++, auxr++){
		scanf("%lld", &v[i]);
		// dbg(bitset<1ll0>(v[i]));
		for(int j = 0;j < 20;j++)
			on[i][j] = ((v[i] >> j) & 1ll);
		if((i % MAXR == 0 && i != 0) || i == n - 1ll){
			for(int j = 0;j < 20;j++)
				b[aux][j] = block(auxl, auxr - (i != n - 1ll), j, aux);
			aux++;
			auxl = i;
		}
	}

	for(int j = 0;j < 20;j++){
		vector<int> k;
		for(int i = 0;i < n;i++){
			if(((v[i] >> j) & 1ll) && (i == 0 || !((v[i - 1ll] >> j) & 1ll)))
				k.push_back(i);
			if(((v[i] >> j) & 1ll) && (i == n - 1ll || !((v[i + 1ll] >> j) & 1ll)))
				k.push_back(i);
		}
		// dbg(k);
		if(k.size() == 0) continue;
		for(int i = 0;i < k.size();i += 2)
			ans += g(k[i + 1ll] - k[i] + 1ll, j);

	}

	while(m--){
		int p, x;
		scanf("%lld %lld", &p, &x), p--;

		for(int i = 0;i < 20;i++)
			update(p % MAXR, (x >> i) & 1ll, p/MAXR, i, b[p/MAXR][i].sz);

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


#include <bits/stdc++.h>

using namespace std;
#define int long long
const int MAXN = 100100, MAXR = 320;

int n, m, ans, lb, v[MAXN];
bool on[MAXN][20];

int g(int x, int bit){
	if(x % 2 == 0)
		return (x / 2ll) * (x + 1ll) * (1ll << bit);
	return ((x + 1ll) / 2ll) * x * (1ll << bit);
}

struct block{
	bool f, a[MAXR];
	int l, r, id, bit, sz;

	block(int l, int r, int bit, int aux) : l(l), r(r), bit(bit), id(aux), f(0) {
		// cout << "Criando o block " << aux << " " << bit << " {l, r} = " << l << " " << r << "\n";
		for(int i = l, pos = 0;i <= r;i++, pos++){
			a[pos] = on[i][bit], f = max(f, on[i][bit]), sz = pos;
			// dbg(a[pos], pos);
		}
		sz++;
		// dbg(sz);
	}

	block(){};
} b[MAXR][20];

void update(int pos, int x, int id, int bit, int sz){
	if(b[id][bit].a[pos] == x)
		return;

	/*dbg(pos, x, id, bit, sz);
	for(int i = 0;i < b[id][bit].sz;i++)
		cout << b[id][bit].a[i] << " ";
	cout << "\n";*/
	int lz = -1ll, rz = n;
	for(int i = pos - 1ll;i >= 0;i--)
		if(b[id][bit].a[i] == 0){
			lz = MAXR * id + i;
			break;
		}
	if(lz == -1ll && id != 0){
		int aux = id - 1ll;
		while(aux >= 0 && b[aux][bit].f == 0ll)
			aux--;
		if(aux == -1ll)
			lz = -1ll;
		else for(int i = b[aux][bit].sz - 1ll;i >= 0;i--)
			if(b[aux][bit].a[i] == 0){
				lz = MAXR * aux + i;
				break;
			}
	}

	for(int i = pos + 1ll;i < sz;i++)
		if(b[id][bit].a[i] == 0){
			rz = MAXR * id + i;
			break;
		}
	if(rz == n && id != lb){
		int aux = id + 1ll;
		while(aux <= lb && b[aux][bit].f == 0ll)
			aux++;
		if(aux > lb)
			rz = n;
		else for(int i = 0;i < sz;i++)
			if(b[aux][bit].a[i] == 0){
				rz = MAXR * aux + i;
				break;
			}
	}

	b[id][bit].a[pos] = !b[id][bit].a[pos];
	if(b[id][bit].a[pos] == 1ll){
		// dbg(lz, rz, pos, bit);
		ans += g(rz - lz - 1ll, bit);
		ans -= g(pos - lz - 1ll, bit);
		ans -= g(rz - pos - 1ll, bit);
		// dbg(ans);
	} else {
		// dbg(lz, rz, pos, bit);
		ans += g(pos - lz - 1ll, bit);
		ans += g(rz - pos - 1ll, bit);
		ans -= g(rz - lz - 1ll, bit);
		// dbg(ans);
	}

	bool ok = 0;
	for(int i = 0;i < b[id][bit].sz;i++)
		if(b[id][bit].a[i] == 0)
			ok = b[id][bit].f = 1ll;
	if(!ok)
		b[id][bit].f = 0;

	// cout << "\n";
}

signed main(){
	scanf("%lld %lld", &n, &m);
	int auxl = 0, auxr = 0, aux = 0;
	lb = (n - 1ll) / MAXR;
	for(int i = 0;i < n;i++, auxr++){
		scanf("%lld", &v[i]);
		// dbg(bitset<1ll0>(v[i]));
		for(int j = 0;j < 20;j++)
			on[i][j] = ((v[i] >> j) & 1ll);
		if((i % MAXR == 0 && i != 0) || i == n - 1ll){
			for(int j = 0;j < 20;j++)
				b[aux][j] = block(auxl, auxr - (i != n - 1ll), j, aux);
			aux++;
			auxl = i;
		}
	}

	for(int j = 0;j < 20;j++){
		vector<int> k;
		for(int i = 0;i < n;i++){
			if(((v[i] >> j) & 1ll) && (i == 0 || !((v[i - 1ll] >> j) & 1ll)))
				k.push_back(i);
			if(((v[i] >> j) & 1ll) && (i == n - 1ll || !((v[i + 1ll] >> j) & 1ll)))
				k.push_back(i);
		}
		// dbg(k);
		if(k.size() == 0) continue;
		for(int i = 0;i < k.size();i += 2)
			ans += g(k[i + 1ll] - k[i] + 1ll, j);

	}
	if(n == 1e5) cout << (ans) << "\n";

	while(m--){
		int p, x;
		scanf("%lld %lld", &p, &x), p--;

		for(int i = 0;i < 20;i++)
			update(p % MAXR, (x >> i) & 1ll, p/MAXR, i, b[p/MAXR][i].sz);

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


#include<bits/stdc++.h>

using namespace std;
const int MAXN = 100100;
const int INF = 0x3f3f3f3f;

int v[MAXN];

struct seg{
	seg *fe,*fd;
	int l,r,meio,soma;

	seg(int x,int y){
		l = x , r = y;
		meio = (x + y) / 2;
		soma = 0;

		if(l == r) return;

		fe = new seg(x,meio);
		fd = new seg(meio + 1,y);
	}

	void up(int pos,int novo){
		if(l == r){
			soma = novo;
			return;
		}
		if(pos <= meio) fe->up(pos,novo);
		else fd->up(pos,novo);

		soma = fe->soma + fd->soma;
	}

	int get(int a,int b){
		if(l >= a && r <= b) return soma;
		if(l > b || r < a) return 0;
		return fe->get(a,b) + fd->get(a,b);
	}

	int getd(int a){
		if(l == r) return l;
		if(fe->soma >= a) return fe->getd(a);
		return fd->getd(a - fe->soma);
	}

	int gete(int a){
		if(l == r) return l;
		if(fd->soma >= a) return fd->gete(a);
		return fe->gete(a - fd->soma);
	}
};

seg *st[17];

signed main(){

	int n,m;
	scanf("%d %d",&n,&m);

	/*seg Seg(0,MAXN);

	Seg.up(0,1) , Seg.up(n + 1 , 1);

	for(int i = 1;i <= n;i++){
		int x;
		cin >> x;
		if(x == 0) Seg.up(i,1);
	}

	for(int i = 1;i <= m;i++){
		int x;
		cin >> x;
		int sl = Seg.get(x,n + 1) , sr = Seg.get(0,x);
		cout << "AA " << sl << " " << sr << endl;
		cout << "/ " << Seg.gete(sl + 1) << " " << Seg.getd(sr + 1) << endl;
	}*/

	v[n + 1] = 0;
	for(int i = 1;i <= n;i++) scanf("%d",&v[i]);

	for(int i = 0;i < 17;i++) st[i] = new seg(0,MAXN);

	long long soma = 0 , resp = 0;
	for(int j = 0;j < 17;j++){
		st[j]->up(0,1) , st[j]->up(n + 1,1);
		for(int i = 1;i <= n+1;i++){
			if((v[i] & (1 << j)) == 0) resp += ((soma * (soma + 1)) / 2) * ((long long) 1 << j) , soma = 0 , st[j]->up(i,1);
			else soma ++;
		}
		soma = 0;
	}

	if(n == 1e5) cout << resp << "\n";

	for(int i = 1;i <= m;i++){
		int y;
		long long x;
		scanf("%lld %d",&x,&y);

		for(int j = 0;j < 17;j++){
			int a = (y & (1 << j));
			int b = (v[x] & (1 << j));
			if(a > 0) a = 1;
			if(b > 0) b = 1;

			if(a == b) continue;
			if(b == 1){
				int sl = st[j]->get(x,n + 1) , sr = st[j]->get(0,x);

				long long l = st[j]->gete(sl + 1);
				long long r = st[j]->getd(sr + 1);

				// if(n == 1e5) cout << "/ " << l << " " << r << endl;

				if(l == r) resp --;
				else{
					resp -= (((r - l - 1) * (r - l)) / 2) * (1 << j);
					if(n == 1e5) cout << "Subtrai " << (((r - l - 1) * (r - l)) / 2) * (1 << j) << "\n" << resp << "\n";
					resp += ((((r - x - 1) * (r - x)) / 2) + (((x - l - 1) * (x - l)) / 2)) * (1 << j);
					if(n == 1e5) cout << "Soma " << ((((r - x - 1) * (r - x)) / 2) + (((x - l - 1) * (x - l)) / 2)) * (1 << j) << "\n" << resp << "\n";
				}

				st[j]->up(x,1);
				continue;
			}
			else{
				int sl = st[j]->get(x,n + 1) , sr = st[j]->get(0,x);

				long long r = st[j]->getd(sr + 1);
				long long l = st[j]->gete(sl + 1);

				// if(n == 1e5) cout << "| " << l << " " << r << endl;

				resp -= (((x - 1 - l) * (x - l)) / 2 + ((r - (x + 1)) * (r - x)) / 2) * (1 << j);
				if(n == 1e5) cout << "Subtrai " << (((x - 1 - l) * (x - l)) / 2 + ((r - (x + 1)) * (r - x)) / 2) * (1 << j) << "\n" << resp << "\n";
				resp += (((r - l - 1) * (r - l)) / 2) * (1 << j);
				if(n == 1e5) cout << "Soma " << (((r - l - 1) * (r - l)) / 2) * (1 << j) << "\n" << resp << "\n";

				st[j]->up(x,0);
			}
		}

		printf("%lld\n",resp);
		v[x] = y;
	}
}


#include<bits/stdc++.h>

using namespace std;
const int MAXN = 100100;
const int INF = 0x3f3f3f3f;

int v[MAXN];

struct seg{
	seg *fe,*fd;
	int l,r,meio,soma;

	seg(int x,int y){
		l = x , r = y;
		meio = (x + y) / 2;
		soma = 0;

		if(l == r) return;

		fe = new seg(x,meio);
		fd = new seg(meio + 1,y);
	}

	void up(int pos,int novo){
		if(l == r){
			soma = novo;
			return;
		}
		if(pos <= meio) fe->up(pos,novo);
		else fd->up(pos,novo);

		soma = fe->soma + fd->soma;
	}

	int get(int a,int b){
		if(l >= a && r <= b) return soma;
		if(l > b || r < a) return 0;
		return fe->get(a,b) + fd->get(a,b);
	}

	int getd(int a){
		if(l == r) return l;
		if(fe->soma >= a) return fe->getd(a);
		return fd->getd(a - fe->soma);
	}

	int gete(int a){
		if(l == r) return l;
		if(fd->soma >= a) return fd->gete(a);
		return fe->gete(a - fd->soma);
	}
};

seg *st[17];

signed main(){

	int n,m;
	scanf("%d %d",&n,&m);

	/*seg Seg(0,MAXN);

	Seg.up(0,1) , Seg.up(n + 1 , 1);

	for(int i = 1;i <= n;i++){
		int x;
		cin >> x;
		if(x == 0) Seg.up(i,1);
	}

	for(int i = 1;i <= m;i++){
		int x;
		cin >> x;
		int sl = Seg.get(x,n + 1) , sr = Seg.get(0,x);
		cout << "AA " << sl << " " << sr << endl;
		cout << "/ " << Seg.gete(sl + 1) << " " << Seg.getd(sr + 1) << endl;
	}*/

	v[n + 1] = 0;
	for(int i = 1;i <= n;i++) scanf("%d",&v[i]);

	for(int i = 0;i < 17;i++) st[i] = new seg(0,MAXN);

	long long soma = 0 , resp = 0;
	for(int j = 0;j < 17;j++){
		st[j]->up(0,1) , st[j]->up(n + 1,1);
		for(int i = 1;i <= n+1;i++){
			if((v[i] & (1 << j)) == 0) resp += ((soma * (soma + 1)) / 2) * ((long long) 1 << j) , soma = 0 , st[j]->up(i,1);
			else soma ++;
		}
		soma = 0;
	}

	bool okk = (n == 1e5 && m == 1e5 && v[1] == 1e5);

	for(int i = 1;i <= m;i++){
		int y;
		long long x;
		scanf("%lld %d",&x,&y);

		for(int j = 0;j < 17;j++){
			int a = (y & (1 << j));
			int b = (v[x] & (1 << j));
			if(a > 0) a = 1;
			if(b > 0) b = 1;

			if(a == b) continue;
			if(b == 1){
				int sl = st[j]->get(x,n + 1) , sr = st[j]->get(0,x);

				long long l = st[j]->gete(sl + 1);
				long long r = st[j]->getd(sr + 1);

				if(okk) cout << l << " " << x << " " << r << "\n";
				// if(n == 1e5) cout << "/ " << l << " " << r << endl;

				if(l == r) resp --;
				else{
					resp -= (((r - l - 1) * (r - l)) / 2) * (1 << j);
					// if(n == 1e5) cout << "Subtrai " << (((r - l - 1) * (r - l)) / 2) * (1 << j) << "\n" << resp << "\n";
					resp += ((((r - x - 1) * (r - x)) / 2) + (((x - l - 1) * (x - l)) / 2)) * (1 << j);
					// if(n == 1e5) cout << "Soma " << ((((r - x - 1) * (r - x)) / 2) + (((x - l - 1) * (x - l)) / 2)) * (1 << j) << "\n" << resp << "\n";
				}

				st[j]->up(x,1);
				continue;
			}
			else{
				int sl = st[j]->get(x,n + 1) , sr = st[j]->get(0,x);

				long long r = st[j]->getd(sr + 1);
				long long l = st[j]->gete(sl + 1);

				// if(n == 1e5) cout << "| " << l << " " << r << endl;
				if(okk) cout << l << " " << x << " " << r << "\n";

				resp -= (((x - 1 - l) * (x - l)) / 2 + ((r - (x + 1)) * (r - x)) / 2) * (1 << j);
				// if(n == 1e5) cout << "Subtrai " << (((x - 1 - l) * (x - l)) / 2 + ((r - (x + 1)) * (r - x)) / 2) * (1 << j) << "\n" << resp << "\n";
				resp += (((r - l - 1) * (r - l)) / 2) * (1 << j);
				// if(n == 1e5) cout << "Soma " << (((r - l - 1) * (r - l)) / 2) * (1 << j) << "\n" << resp << "\n";

				st[j]->up(x,0);
			}
		}

		printf("%lld\n",resp);
		v[x] = y;
	}
}


#include <bits/stdc++.h>

using namespace std;
#define int long long
const int MAXN = 100100, MAXR = 320;

int n, m, ans, lb, v[MAXN];
bool on[MAXN][20];

int g(int x, int bit){
	if(x % 2 == 0)
		return (x / 2ll) * (x + 1ll) * (1ll << bit);
	return ((x + 1ll) / 2ll) * x * (1ll << bit);
}

struct block{
	bool f, a[MAXR];
	int l, r, id, bit, sz;

	block(int l, int r, int bit, int aux) : l(l), r(r), bit(bit), id(aux), f(0) {
		// cout << "Criando o block " << aux << " " << bit << " {l, r} = " << l << " " << r << "\n";
		for(int i = l, pos = 0;i <= r;i++, pos++){
			a[pos] = on[i][bit], f = max(f, on[i][bit]), sz = pos;
			// dbg(a[pos], pos);
		}
		sz++;
		// dbg(sz);
	}

	block(){};
} b[MAXR][20];

void update(int pos, int x, int id, int bit, int sz){
	if(b[id][bit].a[pos] == x)
		return;

	/*dbg(pos, x, id, bit, sz);
	for(int i = 0;i < b[id][bit].sz;i++)
		cout << b[id][bit].a[i] << " ";
	cout << "\n";*/
	int lz = -1ll, rz = n;
	for(int i = pos - 1ll;i >= 0;i--)
		if(b[id][bit].a[i] == 0){
			lz = MAXR * id + i;
			break;
		}
	if(lz == -1ll && id != 0){
		int aux = id - 1ll;
		while(aux >= 0 && b[aux][bit].f == 0ll)
			aux--;
		if(aux == -1ll)
			lz = -1ll;
		else for(int i = b[aux][bit].sz - 1ll;i >= 0;i--)
			if(b[aux][bit].a[i] == 0){
				lz = MAXR * aux + i;
				break;
			}
	}

	for(int i = pos + 1ll;i < sz;i++)
		if(b[id][bit].a[i] == 0){
			rz = MAXR * id + i;
			break;
		}
	if(rz == n && id != lb){
		int aux = id + 1ll;
		while(aux <= lb && b[aux][bit].f == 0ll)
			aux++;
		if(aux > lb)
			rz = n;
		else for(int i = 0;i < sz;i++)
			if(b[aux][bit].a[i] == 0){
				rz = MAXR * aux + i;
				break;
			}
	}

	b[id][bit].a[pos] = !b[id][bit].a[pos];
	if(b[id][bit].a[pos] == 1ll){
		pos = MAXR * id + pos;
		// dbg(lz, rz, pos, bit);
		ans -= g(pos - lz - 1ll, bit) + g(rz - pos - 1ll, bit);
		if(n == 1e5 && m == 1e5 && v[0] == 1e5) cout << "S: " << g(pos - lz - 1ll, bit) + g(rz - pos - 1ll, bit) << "\n" << "ans = " << ans << "\n";
		ans += g(rz - lz - 1ll, bit);
		if(n == 1e5 && m == 1e5 && v[0] == 1e5) cout << "So: " << g(rz - lz - 1ll, bit) << "\n" << "ans = " << ans << "\n";
		// dbg(ans);
	} else {
		pos = MAXR * id + pos;
		// dbg(lz, rz, pos, bit);
		ans += g(pos - lz - 1ll, bit) + g(rz - pos - 1ll, bit);
		if(n == 1e5 && m == 1e5 && v[0] == 1e5) cout << "So: " << g(pos - lz - 1ll, bit) + g(rz - pos - 1ll, bit) << "\n" << "ans = " << ans << "\n";
		ans -= g(rz - lz - 1ll, bit);
		if(n == 1e5 && m == 1e5 && v[0] == 1e5) cout << "S: " << g(rz - lz - 1ll, bit) << "\n" << "ans = " << ans << "\n";
		// dbg(ans);
	}

	bool ok = 0;
	for(int i = 0;i < b[id][bit].sz;i++)
		if(b[id][bit].a[i] == 0)
			ok = b[id][bit].f = 1ll;
	if(!ok)
		b[id][bit].f = 0;

	// cout << "\n";
}

signed main(){
	scanf("%lld %lld", &n, &m);
	int auxl = 0, auxr = 0, aux = 0;
	lb = (n - 1ll) / MAXR;
	for(int i = 0;i < n;i++, auxr++){
		scanf("%lld", &v[i]);
		// dbg(bitset<1ll0>(v[i]));
		for(int j = 0;j < 20;j++)
			on[i][j] = ((v[i] >> j) & 1ll);
		if((i % MAXR == 0 && i != 0) || i == n - 1ll){
			for(int j = 0;j < 20;j++)
				b[aux][j] = block(auxl, auxr - (i != n - 1ll), j, aux);
			aux++;
			auxl = i;
		}
	}

	for(int j = 0;j < 20;j++){
		vector<int> k;
		for(int i = 0;i < n;i++){
			if(((v[i] >> j) & 1ll) && (i == 0 || !((v[i - 1ll] >> j) & 1ll)))
				k.push_back(i);
			if(((v[i] >> j) & 1ll) && (i == n - 1ll || !((v[i + 1ll] >> j) & 1ll)))
				k.push_back(i);
		}
		// dbg(k);
		if(k.size() == 0) continue;
		for(int i = 0;i < k.size();i += 2)
			ans += g(k[i + 1ll] - k[i] + 1ll, j);

	}

	if(n == 1e5 && m == 1e5 && v[0] == 1e5) cout << "ans = //" << ans << "\n";

	while(m--){
		if(n == 1e5 && m == 1e5 && v[0] == 1e5) cout << "m = " << m << "\n";
		int p, x;
		scanf("%lld %lld", &p, &x), p--;
		if(n == 1e5 && m == 1e5 && v[0] == 1e5) cout << "p, x " << p << " " << x << "\n";

		for(int i = 0;i < 20;i++){
			if(n == 1e5 && m == 1e5 && v[0] == 1e5) cout << "oi\n";
			update(p % MAXR, (x >> i) & 1ll, p/MAXR, i, b[p/MAXR][i].sz);
		}

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


#include <bits/stdc++.h>

using namespace std;
#define int long long
const int MAXN = 100100, MAXR = 320;

int n, m, ans, lb, v[MAXN];
bool on[MAXN][20];

int g(int x, int bit){
	if(x % 2 == 0)
		return (x / 2ll) * (x + 1ll) * (1ll << bit);
	return ((x + 1ll) / 2ll) * x * (1ll << bit);
}

struct block{
	bool f, a[MAXR];
	int l, r, id, bit, sz;

	block(int l, int r, int bit, int aux) : l(l), r(r), bit(bit), id(aux), f(0) {
		// cout << "Criando o block " << aux << " " << bit << " {l, r} = " << l << " " << r << "\n";
		for(int i = l, pos = 0;i <= r;i++, pos++){
			a[pos] = on[i][bit], f = max(f, on[i][bit]), sz = pos;
			// dbg(a[pos], pos);
		}
		sz++;
		// dbg(sz);
	}

	block(){};
} b[MAXR][20];

void update(int pos, int x, int id, int bit, int sz){
	if(b[id][bit].a[pos] == x)
		return;

	/*dbg(pos, x, id, bit, sz);
	for(int i = 0;i < b[id][bit].sz;i++)
		cout << b[id][bit].a[i] << " ";
	cout << "\n";*/
	int lz = -1ll, rz = n;
	for(int i = pos - 1ll;i >= 0;i--)
		if(b[id][bit].a[i] == 0){
			lz = MAXR * id + i;
			break;
		}
	if(lz == -1ll && id != 0){
		int aux = id - 1ll;
		while(aux >= 0 && b[aux][bit].f == 0ll)
			aux--;
		if(aux == -1ll)
			lz = -1ll;
		else for(int i = b[aux][bit].sz - 1ll;i >= 0;i--)
			if(b[aux][bit].a[i] == 0){
				lz = MAXR * aux + i;
				break;
			}
	}

	for(int i = pos + 1ll;i < sz;i++)
		if(b[id][bit].a[i] == 0){
			rz = MAXR * id + i;
			break;
		}
	if(rz == n && id != lb){
		int aux = id + 1ll;
		while(aux <= lb && b[aux][bit].f == 0ll)
			aux++;
		if(aux > lb)
			rz = n;
		else for(int i = 0;i < sz;i++)
			if(b[aux][bit].a[i] == 0){
				rz = MAXR * aux + i;
				break;
			}
	}

	b[id][bit].a[pos] = !b[id][bit].a[pos];
	if(b[id][bit].a[pos] == 1ll){
		// dbg(lz, rz, pos, bit);
		ans += g(rz - lz - 1ll, bit);
		ans -= g(pos - lz - 1ll, bit);
		ans -= g(rz - pos - 1ll, bit);
		// dbg(ans);
	} else {
		// dbg(lz, rz, pos, bit);
		ans += g(pos - lz - 1ll, bit);
		ans += g(rz - pos - 1ll, bit);
		ans -= g(rz - lz - 1ll, bit);
		// dbg(ans);
	}
	if(n == 1e5) cout << lz << " " << rz << "\n";

	bool ok = 0;
	for(int i = 0;i < b[id][bit].sz;i++)
		if(b[id][bit].a[i] == 0)
			ok = b[id][bit].f = 1ll;
	if(!ok)
		b[id][bit].f = 0;

	// cout << "\n";
}

signed main(){
	scanf("%lld %lld", &n, &m);
	int auxl = 0, auxr = 0, aux = 0;
	lb = (n - 1ll) / MAXR;
	for(int i = 0;i < n;i++, auxr++){
		scanf("%lld", &v[i]);
		// dbg(bitset<1ll0>(v[i]));
		for(int j = 0;j < 20;j++)
			on[i][j] = ((v[i] >> j) & 1ll);
		if((i % MAXR == 0 && i != 0) || i == n - 1ll){
			for(int j = 0;j < 20;j++)
				b[aux][j] = block(auxl, auxr - (i != n - 1ll), j, aux);
			aux++;
			auxl = i;
		}
	}

	for(int j = 0;j < 20;j++){
		vector<int> k;
		for(int i = 0;i < n;i++){
			if(((v[i] >> j) & 1ll) && (i == 0 || !((v[i - 1ll] >> j) & 1ll)))
				k.push_back(i);
			if(((v[i] >> j) & 1ll) && (i == n - 1ll || !((v[i + 1ll] >> j) & 1ll)))
				k.push_back(i);
		}
		// dbg(k);
		if(k.size() == 0) continue;
		for(int i = 0;i < k.size();i += 2)
			ans += g(k[i + 1ll] - k[i] + 1ll, j);

	}
	if(n == 1e5) cout << (ans) << "\n";

	while(m--){
		int p, x;
		scanf("%lld %lld", &p, &x), p--;

		for(int i = 0;i < 20;i++)
			update(p % MAXR, (x >> i) & 1ll, p/MAXR, i, b[p/MAXR][i].sz);

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


#include <bits/stdc++.h>

using namespace std;
#define int long long
const int MAXN = 100100, MAXR = 320;

int n, m, ans, lb, v[MAXN];
bool on[MAXN][20];

int g(int x, int bit){
	if(x % 2 == 0)
		return (x / 2ll) * (x + 1ll) * (1ll << bit);
	return ((x + 1ll) / 2ll) * x * (1ll << bit);
}

struct block{
	bool f, a[MAXR];
	int l, r, id, bit, sz;

	block(int l, int r, int bit, int aux) : l(l), r(r), bit(bit), id(aux), f(0) {
		// cout << "Criando o block " << aux << " " << bit << " {l, r} = " << l << " " << r << "\n";
		for(int i = l, pos = 0;i <= r;i++, pos++){
			a[pos] = on[i][bit], f = max(f, on[i][bit]), sz = pos;
			// dbg(a[pos], pos);
		}
		sz++;
		// dbg(sz);
	}

	block(){};
} b[MAXR][20];

void update(int pos, int x, int id, int bit, int sz){
	if(b[id][bit].a[pos] == x)
		return;

	/*dbg(pos, x, id, bit, sz);
	for(int i = 0;i < b[id][bit].sz;i++)
		cout << b[id][bit].a[i] << " ";
	cout << "\n";*/
	int lz = -1ll, rz = n;
	for(int i = pos - 1ll;i >= 0;i--)
		if(b[id][bit].a[i] == 0){
			lz = MAXR * id + i;
			break;
		}
	if(lz == -1ll && id != 0){
		int aux = id - 1ll;
		while(aux >= 0 && b[aux][bit].f == 0ll)
			aux--;
		if(aux == -1ll)
			lz = -1ll;
		else for(int i = b[aux][bit].sz - 1ll;i >= 0;i--)
			if(b[aux][bit].a[i] == 0){
				lz = MAXR * aux + i;
				break;
			}
	}

	for(int i = pos + 1ll;i < sz;i++)
		if(b[id][bit].a[i] == 0){
			rz = MAXR * id + i;
			break;
		}
	if(rz == n && id != lb){
		int aux = id + 1ll;
		while(aux <= lb && b[aux][bit].f == 0ll)
			aux++;
		if(aux > lb)
			rz = n;
		else for(int i = 0;i < sz;i++)
			if(b[aux][bit].a[i] == 0){
				rz = MAXR * aux + i;
				break;
			}
	}

	b[id][bit].a[pos] = !b[id][bit].a[pos];
	if(b[id][bit].a[pos] == 1ll){
		// dbg(lz, rz, pos, bit);
		ans -= g(pos - lz - 1ll, bit);
		ans -= g(rz - pos - 1ll, bit);
		ans += g(rz - lz - 1ll, bit);
		// dbg(ans);
	} else {
		// dbg(lz, rz, pos, bit);
		ans -= g(rz - lz - 1ll, bit);
		ans += g(pos - lz - 1ll, bit);
		ans += g(rz - pos - 1ll, bit);
		// dbg(ans);
	}

	bool ok = 0;
	for(int i = 0;i < b[id][bit].sz;i++)
		if(b[id][bit].a[i] == 0)
			ok = b[id][bit].f = 1ll;
	if(!ok)
		b[id][bit].f = 0;

	// cout << "\n";
}

signed main(){
	scanf("%lld %lld", &n, &m);
	int auxl = 0, auxr = 0, aux = 0;
	lb = (n - 1ll) / MAXR;
	for(int i = 0;i < n;i++, auxr++){
		scanf("%lld", &v[i]);
		// dbg(bitset<1ll0>(v[i]));
		for(int j = 0;j < 20;j++)
			on[i][j] = ((v[i] >> j) & 1ll);
		if((i % MAXR == 0 && i != 0) || i == n - 1ll){
			for(int j = 0;j < 20;j++)
				b[aux][j] = block(auxl, auxr - (i != n - 1ll), j, aux);
			aux++;
			auxl = i;
		}
	}

	for(int j = 0;j < 20;j++){
		vector<int> k;
		for(int i = 0;i < n;i++){
			if(((v[i] >> j) & 1ll) && (i == 0 || !((v[i - 1ll] >> j) & 1ll)))
				k.push_back(i);
			if(((v[i] >> j) & 1ll) && (i == n - 1ll || !((v[i + 1ll] >> j) & 1ll)))
				k.push_back(i);
		}
		// dbg(k);
		if(k.size() == 0) continue;
		for(int i = 0;i < k.size();i += 2)
			ans += g(k[i + 1ll] - k[i] + 1ll, j);

	}
	// dbg(ans);

	while(m--){
		int p, x;
		scanf("%lld %lld", &p, &x), p--;

		for(int i = 0;i < 20;i++)
			update(p % MAXR, (x >> i) & 1ll, p/MAXR, i, b[p/MAXR][i].sz);

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


#include <bits/stdc++.h>

using namespace std;
const int MAXN = 100100, MAXR = 320;

#define int long long
int n, m, ans, lb, v[MAXN];
bool on[MAXN][20];

int g(int x, int bit){
	return ((x * (x + 1ll)) / 2ll) * (1ll << bit);
}

struct block{
	bool f, a[MAXR];
	int l, r, id, bit, sz;

	block(int l, int r, int bit, int aux) : l(l), r(r), bit(bit), id(aux), f(0) {
		// cout << "Criando o block " << aux << " " << bit << " {l, r} = " << l << " " << r << "\n";
		for(int i = l, pos = 0;i <= r;i++, pos++){
			a[pos] = on[i][bit], f = max(f, on[i][bit]), sz = pos;
			// dbg(a[pos], pos);
		}
		sz++;
		// dbg(sz);
	}

	block(){};
} b[MAXR][20];

void update(int pos, int x, int id, int bit, int sz){
	if(b[id][bit].a[pos] == x)
		return;

	/*dbg(pos, x, id, bit, sz);
	for(int i = 0;i < b[id][bit].sz;i++)
		cout << b[id][bit].a[i] << " ";
	cout << "\n";*/
	int lz = -1ll, rz = n;
	for(int i = pos - 1ll;i >= 0;i--)
		if(b[id][bit].a[i] == 0){
			lz = MAXR * id + i;
			break;
		}
	if(lz == -1ll && id != 0){
		int aux = id - 1ll;
		while(aux >= 0 && b[aux][bit].f == 1ll)
			aux--;
		if(aux == -1ll)
			lz = -1ll;
		else for(int i = b[aux][bit].sz - 1ll;i >= 0;i--)
			if(b[aux][bit].a[i] == 0){
				lz = MAXR * aux + i;
				break;
			}
	}

	for(int i = pos + 1ll;i < sz;i++)
		if(b[id][bit].a[i] == 0){
			rz = MAXR * id + i;
			break;
		}
	if(rz == n && id != lb){
		int aux = id + 1ll;
		while(aux <= lb && b[aux][bit].f == 1ll)
			aux++;
		if(aux > lb)
			rz = n;
		else for(int i = 0;i < sz;i++)
			if(b[aux][bit].a[i] == 0){
				rz = MAXR * aux + i;
				break;
			}
	}

	b[id][bit].a[pos] = !b[id][bit].a[pos];
	if(b[id][bit].a[pos] == 1ll){
		// dbg(lz, rz, pos, bit);
		ans -= g(pos - lz - 1ll, bit);
		ans -= g(rz - pos - 1ll, bit);
		ans += g(rz - lz - 1ll, bit);
		// dbg(ans);
	} else {
		// dbg(lz, rz, pos, bit);
		ans -= g(rz - lz - 1ll, bit);
		ans += g(pos - lz - 1ll, bit);
		ans += g(rz - pos - 1ll, bit);
		// dbg(ans);
	}

	bool ok = 0;
	for(int i = 0;i < b[id][bit].sz;i++)
		if(b[id][bit].a[i] == 0)
			ok = b[id][bit].f = 1ll;
	if(!ok)
		b[id][bit].f = 0;

	// cout << "\n";
}

signed main(){
	scanf("%lld %lld", &n, &m);
	int auxl = 0, auxr = 0, aux = 0;
	lb = (n - 1ll) / MAXR;
	for(int i = 0;i < n;i++, auxr++){
		scanf("%lld", &v[i]);
		// dbg(bitset<1ll0>(v[i]));
		for(int j = 0;j < 20;j++)
			on[i][j] = ((v[i] >> j) & 1ll);
		if((i % MAXR == 0 && i != 0) || i == n - 1ll){
			for(int j = 0;j < 20;j++)
				b[aux][j] = block(auxl, auxr - (i != n - 1ll), j, aux);
			aux++;
			auxl = i;
		}
	}

	for(int j = 0;j < 20;j++){
		vector<int> k;
		for(int i = 0;i < n;i++){
			if(((v[i] >> j) & 1ll) && (i == 0 || !((v[i - 1ll] >> j) & 1ll)))
				k.push_back(i);
			if(((v[i] >> j) & 1ll) && (i == n - 1ll || !((v[i + 1ll] >> j) & 1ll)))
				k.push_back(i);
		}
		// dbg(k);
		if(k.size() == 0) continue;
		for(int i = 0;i < k.size();i += 2)
			ans += g(k[i + 1ll] - k[i] + 1ll, j);

	}
	// dbg(ans);

	while(m--){
		int p, x;
		scanf("%lld %lld", &p, &x), p--;

		for(int i = 0;i < 20;i++){
			update(p % MAXR, (x >> i) & 1ll, p/MAXR, i, b[p/MAXR][i].sz);
		}

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


#include <bits/stdc++.h>

using namespace std;
const int MAXN = 100100, MAXR = 320;

#define int long long
int n, m, ans, lb, v[MAXN];
bool on[MAXN][20];

int g(int x, int bit){
	return ((x * (x + 1ll)) / 2ll) * (1ll << bit);
}

struct block{
	bool f, a[MAXR];
	int l, r, id, bit, sz;

	block(int l, int r, int bit, int aux) : l(l), r(r), bit(bit), id(aux), f(0) {
		// cout << "Criando o block " << aux << " " << bit << " {l, r} = " << l << " " << r << "\n";
		for(int i = l, pos = 0;i <= r;i++, pos++){
			a[pos] = on[i][bit], f = max(f, on[i][bit]), sz = pos;
			// dbg(a[pos], pos);
		}
		sz++;
		// dbg(sz);
	}

	block(){};
} b[MAXR][20];

void update(int pos, int x, int id, int bit, int sz){
	if(b[id][bit].a[pos] == x)
		return;

	/*dbg(pos, x, id, bit, sz);
	for(int i = 0;i < b[id][bit].sz;i++)
		cout << b[id][bit].a[i] << " ";
	cout << "\n";*/
	int lz = -1ll, rz = n;
	for(int i = pos - 1ll;i >= 0;i--)
		if(b[id][bit].a[i] == 0){
			lz = MAXR * id + i;
			break;
		}
	if(lz == -1ll && id != 0){
		int aux = id - 1ll;
		while(aux >= 0 && b[aux][bit].f == 0ll)
			aux--;
		if(aux == -1ll)
			lz = -1ll;
		else for(int i = b[aux][bit].sz - 1ll;i >= 0;i--)
			if(b[aux][bit].a[i] == 0){
				lz = MAXR * aux + i;
				break;
			}
	}

	for(int i = pos + 1ll;i < sz;i++)
		if(b[id][bit].a[i] == 0){
			rz = MAXR * id + i;
			break;
		}
	if(rz == n && id != lb){
		int aux = id + 1ll;
		while(aux <= lb && b[aux][bit].f == 0ll)
			aux++;
		if(aux > lb)
			rz = n;
		else for(int i = 0;i < sz;i++)
			if(b[aux][bit].a[i] == 0){
				rz = MAXR * aux + i;
				break;
			}
	}

	b[id][bit].a[pos] = !b[id][bit].a[pos];
	if(b[id][bit].a[pos] == 1ll){
		// dbg(lz, rz, pos, bit);
		ans -= g(pos - lz - 1ll, bit);
		ans -= g(rz - pos - 1ll, bit);
		ans += g(rz - lz - 1ll, bit);
		// dbg(ans);
	} else {
		// dbg(lz, rz, pos, bit);
		ans -= g(rz - lz - 1ll, bit);
		ans += g(pos - lz - 1ll, bit);
		ans += g(rz - pos - 1ll, bit);
		// dbg(ans);
	}

	bool ok = 0;
	for(int i = 0;i < b[id][bit].sz;i++)
		if(b[id][bit].a[i] == 0)
			ok = b[id][bit].f = 1ll;
	if(!ok)
		b[id][bit].f = 0;

	// cout << "\n";
}

signed main(){
	scanf("%lld %lld", &n, &m);
	int auxl = 0, auxr = 0, aux = 0;
	lb = (n - 1ll) / MAXR;
	for(int i = 0;i < n;i++, auxr++){
		scanf("%lld", &v[i]);
		// dbg(bitset<1ll0>(v[i]));
		for(int j = 0;j < 20;j++)
			on[i][j] = ((v[i] >> j) & 1ll);
		if((i % MAXR == 0 && i != 0) || i == n - 1ll){
			for(int j = 0;j < 20;j++)
				b[aux][j] = block(auxl, auxr - (i != n - 1ll), j, aux);
			aux++;
			auxl = i;
		}
	}

	for(int j = 0;j < 20;j++){
		vector<int> k;
		for(int i = 0;i < n;i++){
			if(((v[i] >> j) & 1ll) && (i == 0 || !((v[i - 1ll] >> j) & 1ll)))
				k.push_back(i);
			if(((v[i] >> j) & 1ll) && (i == n - 1ll || !((v[i + 1ll] >> j) & 1ll)))
				k.push_back(i);
		}
		// dbg(k);
		if(k.size() == 0) continue;
		for(int i = 0;i < k.size();i += 2)
			ans += g(k[i + 1ll] - k[i] + 1ll, j);

	}
	// dbg(ans);

	while(m--){
		int p, x;
		scanf("%lld %lld", &p, &x), p--;

		for(int i = 0;i < 20;i++)
			update(p % MAXR, (x >> i) & 1ll, p/MAXR, i, b[p/MAXR][i].sz);

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


#include <bits/stdc++.h>

using namespace std;
#define int long long
const int MAXN = 100100, MAXR = 320;

int n, m, ans, lb, v[MAXN];
bool on[MAXN][20];

int g(int x, int bit){
	if(x % 2 == 0)
		return (x / 2ll) * (x + 1ll) * (1ll << bit);
	return ((x + 1ll) / 2ll) * x * (1ll << bit);
}

struct block{
	bool f, a[MAXR];
	int l, r, id, bit, sz;

	block(int l, int r, int bit, int aux) : l(l), r(r), bit(bit), id(aux), f(0) {
		// cout << "Criando o block " << aux << " " << bit << " {l, r} = " << l << " " << r << "\n";
		for(int i = l, pos = 0;i <= r;i++, pos++){
			a[pos] = on[i][bit], f = max(f, on[i][bit]), sz = pos;
			// dbg(a[pos], pos);
		}
		sz++;
		// dbg(sz);
	}

	block(){};
} b[MAXR][20];

void update(int pos, int x, int id, int bit, int sz){
	if(b[id][bit].a[pos] == x)
		return;

	/*dbg(pos, x, id, bit, sz);
	for(int i = 0;i < b[id][bit].sz;i++)
		cout << b[id][bit].a[i] << " ";
	cout << "\n";*/
	int lz = -1ll, rz = n;
	for(int i = pos - 1ll;i >= 0;i--)
		if(b[id][bit].a[i] == 0){
			lz = MAXR * id + i;
			break;
		}
	if(lz == -1ll && id != 0){
		int aux = id - 1ll;
		while(aux >= 0 && b[aux][bit].f == 0ll)
			aux--;
		if(aux == -1ll)
			lz = -1ll;
		else for(int i = b[aux][bit].sz - 1ll;i >= 0;i--)
			if(b[aux][bit].a[i] == 0){
				lz = MAXR * aux + i;
				break;
			}
	}

	for(int i = pos + 1ll;i < sz;i++)
		if(b[id][bit].a[i] == 0){
			rz = MAXR * id + i;
			break;
		}
	if(rz == n && id != lb){
		int aux = id + 1ll;
		while(aux <= lb && b[aux][bit].f == 0ll)
			aux++;
		if(aux > lb)
			rz = n;
		else for(int i = 0;i < sz;i++)
			if(b[aux][bit].a[i] == 0){
				rz = MAXR * aux + i;
				break;
			}
	}

	b[id][bit].a[pos] = !b[id][bit].a[pos];
	if(b[id][bit].a[pos] == 1ll){
		// dbg(lz, rz, pos, bit);
		ans -= g(pos - lz - 1ll, bit) + g(rz - pos - 1ll, bit);
		if(n == 1e5) cout << "Subtrai " << g(pos - lz - 1ll, bit) + g(rz - pos - 1ll, bit) << "\n" << ans << "\n";
		ans += g(rz - lz - 1ll, bit);
		if(n == 1e5) cout << "Soma " << g(rz - lz - 1ll, bit) << "\n" << ans << "\n";
		// dbg(ans);
	} else {
		// dbg(lz, rz, pos, bit);
		ans += g(pos - lz - 1ll, bit) + g(rz - pos - 1ll, bit);
		if(n == 1e5) cout << "Soma " << g(pos - lz - 1ll, bit) + g(rz - pos - 1ll, bit) << "\n" << ans << "\n";
		ans -= g(rz - lz - 1ll, bit);
		if(n == 1e5) cout << "Subtrai " << g(pos - lz - 1ll, bit) + g(rz - pos - 1ll, bit) << "\n" << ans << "\n";
		// dbg(ans);
	}
	// if(n == 1e5) cout << lz << " " << rz << "\n";

	bool ok = 0;
	for(int i = 0;i < b[id][bit].sz;i++)
		if(b[id][bit].a[i] == 0)
			ok = b[id][bit].f = 1ll;
	if(!ok)
		b[id][bit].f = 0;

	// cout << "\n";
}

signed main(){
	scanf("%lld %lld", &n, &m);
	int auxl = 0, auxr = 0, aux = 0;
	lb = (n - 1ll) / MAXR;
	for(int i = 0;i < n;i++, auxr++){
		scanf("%lld", &v[i]);
		// dbg(bitset<1ll0>(v[i]));
		for(int j = 0;j < 20;j++)
			on[i][j] = ((v[i] >> j) & 1ll);
		if((i % MAXR == 0 && i != 0) || i == n - 1ll){
			for(int j = 0;j < 20;j++)
				b[aux][j] = block(auxl, auxr - (i != n - 1ll), j, aux);
			aux++;
			auxl = i;
		}
	}

	for(int j = 0;j < 20;j++){
		vector<int> k;
		for(int i = 0;i < n;i++){
			if(((v[i] >> j) & 1ll) && (i == 0 || !((v[i - 1ll] >> j) & 1ll)))
				k.push_back(i);
			if(((v[i] >> j) & 1ll) && (i == n - 1ll || !((v[i + 1ll] >> j) & 1ll)))
				k.push_back(i);
		}
		// dbg(k);
		if(k.size() == 0) continue;
		for(int i = 0;i < k.size();i += 2)
			ans += g(k[i + 1ll] - k[i] + 1ll, j);

	}
	if(n == 1e5) cout << (ans) << "\n";

	while(m--){
		int p, x;
		scanf("%lld %lld", &p, &x), p--;

		for(int i = 0;i < 20;i++)
			update(p % MAXR, (x >> i) & 1ll, p/MAXR, i, b[p/MAXR][i].sz);

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


#include <bits/stdc++.h>

using namespace std;
#define int long long
const int MAXN = 100100, MAXR = 320;

int n, m, ans, lb, v[MAXN];
bool on[MAXN][20];

int g(int x, int bit){
	if(x % 2 == 0)
		return (x / 2ll) * (x + 1ll) * (1ll << bit);
	return ((x + 1ll) / 2ll) * x * (1ll << bit);
}

struct block{
	bool f, a[MAXR];
	int l, r, id, bit, sz;

	block(int l, int r, int bit, int aux) : l(l), r(r), bit(bit), id(aux), f(0) {
		// cout << "Criando o block " << aux << " " << bit << " {l, r} = " << l << " " << r << "\n";
		for(int i = l, pos = 0;i <= r;i++, pos++){
			a[pos] = on[i][bit], f = max(f, on[i][bit]), sz = pos;
			// dbg(a[pos], pos);
		}
		sz++;
		// dbg(sz);
	}

	block(){};
} b[MAXR][20];

void update(int pos, int x, int id, int bit, int sz){
	if(b[id][bit].a[pos] == x)
		return;

	/*dbg(pos, x, id, bit, sz);
	for(int i = 0;i < b[id][bit].sz;i++)
		cout << b[id][bit].a[i] << " ";
	cout << "\n";*/
	int lz = -1ll, rz = n;
	for(int i = pos - 1ll;i >= 0;i--)
		if(b[id][bit].a[i] == 0){
			lz = MAXR * id + i;
			break;
		}
	if(lz == -1ll && id != 0){
		int aux = id - 1ll;
		while(aux >= 0 && b[aux][bit].f == 0ll)
			aux--;
		if(aux == -1ll)
			lz = -1ll;
		else for(int i = b[aux][bit].sz - 1ll;i >= 0;i--)
			if(b[aux][bit].a[i] == 0){
				lz = MAXR * aux + i;
				break;
			}
	}

	for(int i = pos + 1ll;i < sz;i++)
		if(b[id][bit].a[i] == 0){
			rz = MAXR * id + i;
			break;
		}
	if(rz == n && id != lb){
		int aux = id + 1ll;
		while(aux <= lb && b[aux][bit].f == 0ll)
			aux++;
		if(aux > lb)
			rz = n;
		else for(int i = 0;i < sz;i++)
			if(b[aux][bit].a[i] == 0){
				rz = MAXR * aux + i;
				break;
			}
	}

	b[id][bit].a[pos] = !b[id][bit].a[pos];
	if(b[id][bit].a[pos] == 1ll){
		pos = MAXR * id + pos;
		// dbg(lz, rz, pos, bit);
		ans -= g(pos - lz - 1ll, bit) + g(rz - pos - 1ll, bit);
		if(n == 1e5 && m == 1e5 && v[0] == 1e5) cout << "S: " << g(pos - lz - 1ll, bit) + g(rz - pos - 1ll, bit) << "\n" << "ans = " << ans << "\n";
		ans += g(rz - lz - 1ll, bit);
		if(n == 1e5 && m == 1e5 && v[0] == 1e5) cout << "So: " << g(rz - lz - 1ll, bit) << "\n" << "ans = " << ans << "\n";
		// dbg(ans);
	} else {
		pos = MAXR * id + pos;
		// dbg(lz, rz, pos, bit);
		ans += g(pos - lz - 1ll, bit) + g(rz - pos - 1ll, bit);
		if(n == 1e5 && m == 1e5 && v[0] == 1e5) cout << "So: " << g(pos - lz - 1ll, bit) + g(rz - pos - 1ll, bit) << "\n" << "ans = " << ans << "\n";
		ans -= g(rz - lz - 1ll, bit);
		if(n == 1e5 && m == 1e5 && v[0] == 1e5) cout << "S: " << g(rz - lz - 1ll, bit) << "\n" << "ans = " << ans << "\n";
		// dbg(ans);
	}

	bool ok = 0;
	for(int i = 0;i < b[id][bit].sz;i++)
		if(b[id][bit].a[i] == 0)
			ok = b[id][bit].f = 1ll;
	if(!ok)
		b[id][bit].f = 0;

	// cout << "\n";
}

signed main(){
	scanf("%lld %lld", &n, &m);
	int auxl = 0, auxr = 0, aux = 0;
	lb = (n - 1ll) / MAXR;
	for(int i = 0;i < n;i++, auxr++){
		scanf("%lld", &v[i]);
		// dbg(bitset<1ll0>(v[i]));
		for(int j = 0;j < 20;j++)
			on[i][j] = ((v[i] >> j) & 1ll);
		if((i % MAXR == 0 && i != 0) || i == n - 1ll){
			for(int j = 0;j < 20;j++)
				b[aux][j] = block(auxl, auxr - (i != n - 1ll), j, aux);
			aux++;
			auxl = i;
		}
	}

	if(n == 1e5 && m == 1e5 && v[0] == 1e5) cout << "ans = " << ans << "\n";

	for(int j = 0;j < 20;j++){
		vector<int> k;
		for(int i = 0;i < n;i++){
			if(((v[i] >> j) & 1ll) && (i == 0 || !((v[i - 1ll] >> j) & 1ll)))
				k.push_back(i);
			if(((v[i] >> j) & 1ll) && (i == n - 1ll || !((v[i + 1ll] >> j) & 1ll)))
				k.push_back(i);
		}
		// dbg(k);
		if(k.size() == 0) continue;
		for(int i = 0;i < k.size();i += 2)
			ans += g(k[i + 1ll] - k[i] + 1ll, j);

	}

	while(m--){
		int p, x;
		scanf("%lld %lld", &p, &x), p--;

		for(int i = 0;i < 20;i++)
			update(p % MAXR, (x >> i) & 1ll, p/MAXR, i, b[p/MAXR][i].sz);

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


#include <bits/stdc++.h>

using namespace std;
#define int long long
const int MAXN = 100100, MAXR = 320;

int n, m, ans, lb, v[MAXN];
bool on[MAXN][20], okk;

int g(int x, int bit){
	if(x % 2 == 0)
		return (x / 2ll) * (x + 1ll) * (1ll << bit);
	return ((x + 1ll) / 2ll) * x * (1ll << bit);
}

struct block{
	bool f, a[MAXR];
	int l, r, id, bit, sz;

	block(int l, int r, int bit, int aux) : l(l), r(r), bit(bit), id(aux), f(0) {
		// cout << "Criando o block " << aux << " " << bit << " {l, r} = " << l << " " << r << "\n";
		for(int i = l, pos = 0;i <= r;i++, pos++){
			a[pos] = on[i][bit], f = (a[pos] == 0 ? 1 : f), sz = pos;
			// dbg(a[pos], pos);
		}
		sz++;
		// dbg(sz);
	}

	block(){};
} b[MAXR][20];

void update(int pos, int x, int id, int bit, int sz){
	if(b[id][bit].a[pos] == x)
		return;

	/*dbg(pos, x, id, bit, sz);
	for(int i = 0;i < b[id][bit].sz;i++)
		cout << b[id][bit].a[i] << " ";
	cout << "\n";*/
	int lz = -1ll, rz = n;
	for(int i = pos - 1ll;i >= 0;i--)
		if(b[id][bit].a[i] == 0){
			lz = MAXR * id + i;
			break;
		}
	if(lz == -1ll && id != 0){
		int aux = id - 1ll;
		while(aux >= 0 && b[aux][bit].f == 1ll)
			aux--;
		if(aux == -1ll)
			lz = -1ll;
		else for(int i = b[aux][bit].sz - 1ll;i >= 0;i--)
			if(b[aux][bit].a[i] == 0){
				lz = MAXR * aux + i;
				break;
			}
	}

	for(int i = pos + 1ll;i < sz;i++)
		if(b[id][bit].a[i] == 0){
			rz = MAXR * id + i;
			break;
		}
	if(rz == n && id != lb){
		int aux = id + 1ll;
		while(aux <= lb && b[aux][bit].f == 1ll)
			aux++;
		if(aux > lb)
			rz = n;
		else for(int i = 0;i < b[aux][bit].sz;i++)
			if(b[aux][bit].a[i] == 0){
				rz = MAXR * aux + i;
				break;
			}
	}

	b[id][bit].a[pos] = x;
	if(b[id][bit].a[pos] == 1ll){
		pos = MAXR * id + pos;
		// dbg(lz, rz, pos, bit);
		ans -= g(pos - lz - 1ll, bit) + g(rz - pos - 1ll, bit);
		// if(okk) cout << "S: " << g(pos - lz - 1ll, bit) + g(rz - pos - 1ll, bit) << "\n" << "ans = " << ans << "\n";
		ans += g(rz - lz - 1ll, bit);
		// if(okk) cout << "So: " << g(rz - lz - 1ll, bit) << "\n" << "ans = " << ans << "\n";
		// dbg(ans);
	} else {
		pos = MAXR * id + pos;
		// dbg(lz, rz, pos, bit);
		ans += g(pos - lz - 1ll, bit) + g(rz - pos - 1ll, bit);
		// if(okk) cout << "So: " << g(pos - lz - 1ll, bit) + g(rz - pos - 1ll, bit) << "\n" << "ans = " << ans << "\n";
		ans -= g(rz - lz - 1ll, bit);
		// if(okk) cout << "S: " << g(rz - lz - 1ll, bit) << "\n" << "ans = " << ans << "\n";
		// dbg(ans);
	}
	// if(okk) cout << "ans: " << ans << "\n";
	// if(okk) cout << lz << " " << pos << " " << rz << "\n";

	bool ok = 0;
	for(int i = 0;i < sz;i++)
		if(b[id][bit].a[i] == 0)
			ok = b[id][bit].f = 1ll;
	if(!ok)
		b[id][bit].f = 0;

	// cout << "\n";
}

signed main(){
	scanf("%lld %lld", &n, &m);
	int auxl = 0, auxr = 0, aux = 0;
	lb = (n - 1ll) / MAXR;
	for(int i = 0;i < n;i++, auxr++){
		scanf("%lld", &v[i]);
		// dbg(bitset<1ll0>(v[i]));
		for(int j = 0;j < 20;j++)
			on[i][j] = ((v[i] >> j) & 1ll);
		if((i % MAXR == 0 && i != 0) || i == n - 1ll){
			for(int j = 0;j < 20;j++)
				b[aux][j] = block(auxl, auxr - (i != n - 1ll), j, aux);
			aux++;
			auxl = i;
		}
	}

	for(int j = 0;j < 20;j++){
		vector<int> k;
		for(int i = 0;i < n;i++){
			if(((v[i] >> j) & 1ll) && (i == 0 || !((v[i - 1ll] >> j) & 1ll)))
				k.push_back(i);
			if(((v[i] >> j) & 1ll) && (i == n - 1ll || !((v[i + 1ll] >> j) & 1ll)))
				k.push_back(i);
		}
		// dbg(k);
		if(k.size() == 0) continue;
		for(int i = 0;i < k.size();i += 2)
			ans += g(k[i + 1ll] - k[i] + 1ll, j);

	}

	// if(n == 1e5 && m == 1e5 && v[0] == 1e5) cout << "ans = //" << ans << "\n";
	okk = (n == 1e5 && m == 1e5 && v[0] == 1e5);

	while(m--){
		int p, x;
		scanf("%lld %lld", &p, &x), p--;

		for(int i = 0;i < 20;i++)
			update(p % MAXR, (x >> i) & 1ll, p/MAXR, i, b[p/MAXR][i].sz);

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


#include<bits/stdc++.h>

using namespace std;
const int MAXN = 100100;
const int INF = 0x3f3f3f3f;

int v[MAXN];

struct seg{
	seg *fe,*fd;
	int l,r,meio,soma;

	seg(int x,int y){
		l = x , r = y;
		meio = (x + y) / 2;
		soma = 0;

		if(l == r) return;

		fe = new seg(x,meio);
		fd = new seg(meio + 1,y);
	}

	void up(int pos,int novo){
		if(l == r){
			soma = novo;
			return;
		}
		if(pos <= meio) fe->up(pos,novo);
		else fd->up(pos,novo);

		soma = fe->soma + fd->soma;
	}

	int get(int a,int b){
		if(l >= a && r <= b) return soma;
		if(l > b || r < a) return 0;
		return fe->get(a,b) + fd->get(a,b);
	}

	int getd(int a){
		if(l == r) return l;
		if(fe->soma >= a) return fe->getd(a);
		return fd->getd(a - fe->soma);
	}

	int gete(int a){
		if(l == r) return l;
		if(fd->soma >= a) return fd->gete(a);
		return fe->gete(a - fd->soma);
	}
};

seg *st[17];

signed main(){

	int n,m;
	scanf("%d %d",&n,&m);

	/*seg Seg(0,MAXN);

	Seg.up(0,1) , Seg.up(n + 1 , 1);

	for(int i = 1;i <= n;i++){
		int x;
		cin >> x;
		if(x == 0) Seg.up(i,1);
	}

	for(int i = 1;i <= m;i++){
		int x;
		cin >> x;
		int sl = Seg.get(x,n + 1) , sr = Seg.get(0,x);
		cout << "AA " << sl << " " << sr << endl;
		cout << "/ " << Seg.gete(sl + 1) << " " << Seg.getd(sr + 1) << endl;
	}*/

	v[n + 1] = 0;
	for(int i = 1;i <= n;i++) scanf("%d",&v[i]);

	for(int i = 0;i < 17;i++) st[i] = new seg(0,MAXN);

	long long soma = 0 , resp = 0;
	for(int j = 0;j < 17;j++){
		st[j]->up(0,1) , st[j]->up(n + 1,1);
		for(int i = 1;i <= n+1;i++){
			if((v[i] & (1 << j)) == 0) resp += ((soma * (soma + 1)) / 2) * ((long long) 1 << j) , soma = 0 , st[j]->up(i,1);
			else soma ++;
		}
		soma = 0;
	}

	if(n == 1e5) cout << resp << "\n";

	for(int i = 1;i <= m;i++){
		int y;
		long long x;
		scanf("%lld %d",&x,&y);

		for(int j = 0;j < 17;j++){
			int a = (y & (1 << j));
			int b = (v[x] & (1 << j));
			if(a > 0) a = 1;
			if(b > 0) b = 1;

			if(a == b) continue;
			if(b == 1){
				int sl = st[j]->get(x,n + 1) , sr = st[j]->get(0,x);

				long long l = st[j]->gete(sl + 1);
				long long r = st[j]->getd(sr + 1);

				// if(n == 1e5) cout << "/ " << l << " " << r << endl;

				if(l == r) resp --;
				else{
					resp -= (((r - l - 1) * (r - l)) / 2) * (1 << j);
					if(n == 1e5) cout << "Subtrai " << (((r - l - 1) * (r - l)) / 2) * (1 << j) << "\n" << resp << "\n";
					resp += ((((r - x - 1) * (r - x)) / 2) + (((x - l - 1) * (x - l)) / 2)) * (1 << j);
					if(n == 1e5) cout << "Soma " << ((((r - x - 1) * (r - x)) / 2) + (((x - l - 1) * (x - l)) / 2)) * (1 << j) << "\n" << resp << "\n";
				}

				st[j]->up(x,1);
				continue;
			}
			else{
				int sl = st[j]->get(x,n + 1) , sr = st[j]->get(0,x);

				long long r = st[j]->getd(sr + 1);
				long long l = st[j]->gete(sl + 1);

				// if(n == 1e5) cout << "| " << l << " " << r << endl;

				resp -= (((x - 1 - l) * (x - l)) / 2 + ((r - (x + 1)) * (r - x)) / 2) * (1 << j);
				if(n == 1e5) cout << "Subtrai " << (((x - 1 - l) * (x - l)) / 2 + ((r - (x + 1)) * (r - x)) / 2) * (1 << j) << "\n" << resp << "\n";
				resp += (((r - l - 1) * (r - l)) / 2) * (1 << j);
				if(n == 1e5) cout << "Soma " << (((r - l - 1) * (r - l)) / 2) * (1 << j) << "\n" << resp << "\n";

				st[j]->up(x,0);
			}
		}

		printf("//%lld\n",resp);
		v[x] = y;
	}
}


#include <bits/stdc++.h>

using namespace std;
const int MAXN = 100100, MAXR = 320;

#define int long long
int n, m, ans, lb, v[MAXN];
bool on[MAXN][20];

int g(int x, int bit){
	if(x % 2 == 0)
		return (x / 2ll) * (x + 1ll) * (1ll << bit);
	return ((x + 1ll) / 2ll) * x * (1ll << bit);
}

struct block{
	bool f, a[MAXR];
	int l, r, id, bit, sz;

	block(int l, int r, int bit, int aux) : l(l), r(r), bit(bit), id(aux), f(0) {
		// cout << "Criando o block " << aux << " " << bit << " {l, r} = " << l << " " << r << "\n";
		for(int i = l, pos = 0;i <= r;i++, pos++){
			a[pos] = on[i][bit], f = max(f, on[i][bit]), sz = pos;
			// dbg(a[pos], pos);
		}
		sz++;
		// dbg(sz);
	}

	block(){};
} b[MAXR][20];

void update(int pos, int x, int id, int bit, int sz){
	if(b[id][bit].a[pos] == x)
		return;

	/*dbg(pos, x, id, bit, sz);
	for(int i = 0;i < b[id][bit].sz;i++)
		cout << b[id][bit].a[i] << " ";
	cout << "\n";*/
	int lz = -1ll, rz = n;
	for(int i = pos - 1ll;i >= 0;i--)
		if(b[id][bit].a[i] == 0){
			lz = MAXR * id + i;
			break;
		}
	if(lz == -1ll && id != 0){
		int aux = id - 1ll;
		while(aux >= 0 && b[aux][bit].f == 0ll)
			aux--;
		if(aux == -1ll)
			lz = -1ll;
		else for(int i = b[aux][bit].sz - 1ll;i >= 0;i--)
			if(b[aux][bit].a[i] == 0){
				lz = MAXR * aux + i;
				break;
			}
	}

	for(int i = pos + 1ll;i < sz;i++)
		if(b[id][bit].a[i] == 0){
			rz = MAXR * id + i;
			break;
		}
	if(rz == n && id != lb){
		int aux = id + 1ll;
		while(aux <= lb && b[aux][bit].f == 0ll)
			aux++;
		if(aux > lb)
			rz = n;
		else for(int i = 0;i < sz;i++)
			if(b[aux][bit].a[i] == 0){
				rz = MAXR * aux + i;
				break;
			}
	}

	b[id][bit].a[pos] = !b[id][bit].a[pos];
	if(b[id][bit].a[pos] == 1ll){
		// dbg(lz, rz, pos, bit);
		ans -= g(pos - lz - 1ll, bit);
		ans -= g(rz - pos - 1ll, bit);
		ans += g(rz - lz - 1ll, bit);
		// dbg(ans);
	} else {
		// dbg(lz, rz, pos, bit);
		ans -= g(rz - lz - 1ll, bit);
		ans += g(pos - lz - 1ll, bit);
		ans += g(rz - pos - 1ll, bit);
		// dbg(ans);
	}

	bool ok = 0;
	for(int i = 0;i < b[id][bit].sz;i++)
		if(b[id][bit].a[i] == 0)
			ok = b[id][bit].f = 1ll;
	if(!ok)
		b[id][bit].f = 0;

	// cout << "\n";
}

signed main(){
	scanf("%lld %lld", &n, &m);
	int auxl = 0, auxr = 0, aux = 0;
	lb = (n - 1ll) / MAXR;
	for(int i = 0;i < n;i++, auxr++){
		scanf("%lld", &v[i]);
		// dbg(bitset<1ll0>(v[i]));
		for(int j = 0;j < 20;j++)
			on[i][j] = ((v[i] >> j) & 1ll);
		if((i % MAXR == 0 && i != 0) || i == n - 1ll){
			for(int j = 0;j < 20;j++)
				b[aux][j] = block(auxl, auxr - (i != n - 1ll), j, aux);
			aux++;
			auxl = i;
		}
	}

	for(int j = 0;j < 20;j++){
		vector<int> k;
		for(int i = 0;i < n;i++){
			if(((v[i] >> j) & 1ll) && (i == 0 || !((v[i - 1ll] >> j) & 1ll)))
				k.push_back(i);
			if(((v[i] >> j) & 1ll) && (i == n - 1ll || !((v[i + 1ll] >> j) & 1ll)))
				k.push_back(i);
		}
		// dbg(k);
		if(k.size() == 0) continue;
		for(int i = 0;i < k.size();i += 2)
			ans += g(k[i + 1ll] - k[i] + 1ll, j);

	}
	// dbg(ans);

	while(m--){
		int p, x;
		scanf("%lld %lld", &p, &x), p--;

		for(int i = 0;i < 20;i++)
			update(p % MAXR, (x >> i) & 1ll, p/MAXR, i, b[p/MAXR][i].sz);

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


#include <bits/stdc++.h>

using namespace std;
#define int long long
const int MAXN = 100100, MAXR = 320;

int n, m, ans, lb, v[MAXN];
bool on[MAXN][20];

int g(int x, int bit){
	if(x % 2 == 0)
		return (x / 2ll) * (x + 1ll) * (1ll << bit);
	return ((x + 1ll) / 2ll) * x * (1ll << bit);
}

struct block{
	bool f, a[MAXR];
	int l, r, id, bit, sz;

	block(int l, int r, int bit, int aux) : l(l), r(r), bit(bit), id(aux), f(0) {
		// cout << "Criando o block " << aux << " " << bit << " {l, r} = " << l << " " << r << "\n";
		for(int i = l, pos = 0;i <= r;i++, pos++){
			a[pos] = on[i][bit], f = max(f, on[i][bit]), sz = pos;
			// dbg(a[pos], pos);
		}
		sz++;
		// dbg(sz);
	}

	block(){};
} b[MAXR][20];

void update(int pos, int x, int id, int bit, int sz){
	if(b[id][bit].a[pos] == x)
		return;

	/*dbg(pos, x, id, bit, sz);
	for(int i = 0;i < b[id][bit].sz;i++)
		cout << b[id][bit].a[i] << " ";
	cout << "\n";*/
	int lz = -1ll, rz = n;
	for(int i = pos - 1ll;i >= 0;i--)
		if(b[id][bit].a[i] == 0){
			lz = MAXR * id + i;
			break;
		}
	if(lz == -1ll && id != 0){
		int aux = id - 1ll;
		while(aux >= 0 && b[aux][bit].f == 0ll)
			aux--;
		if(aux == -1ll)
			lz = -1ll;
		else for(int i = b[aux][bit].sz - 1ll;i >= 0;i--)
			if(b[aux][bit].a[i] == 0){
				lz = MAXR * aux + i;
				break;
			}
	}

	for(int i = pos + 1ll;i < sz;i++)
		if(b[id][bit].a[i] == 0){
			rz = MAXR * id + i;
			break;
		}
	if(rz == n && id != lb){
		int aux = id + 1ll;
		while(aux <= lb && b[aux][bit].f == 0ll)
			aux++;
		if(aux > lb)
			rz = n;
		else for(int i = 0;i < sz;i++)
			if(b[aux][bit].a[i] == 0){
				rz = MAXR * aux + i;
				break;
			}
	}

	b[id][bit].a[pos] = !b[id][bit].a[pos];
	if(b[id][bit].a[pos] == 1ll){
		// dbg(lz, rz, pos, bit);
		ans -= g(pos - lz - 1ll, bit) + g(rz - pos - 1ll, bit);
		ans += g(rz - lz - 1ll, bit);
		// dbg(ans);
	} else {
		// dbg(lz, rz, pos, bit);
		ans += g(pos - lz - 1ll, bit) + g(rz - pos - 1ll, bit);
		ans -= g(rz - lz - 1ll, bit);
		// dbg(ans);
	}
	// if(n == 1e5) cout << lz << " " << rz << "\n";

	bool ok = 0;
	for(int i = 0;i < b[id][bit].sz;i++)
		if(b[id][bit].a[i] == 0)
			ok = b[id][bit].f = 1ll;
	if(!ok)
		b[id][bit].f = 0;

	// cout << "\n";
}

signed main(){
	scanf("%lld %lld", &n, &m);
	int auxl = 0, auxr = 0, aux = 0;
	lb = (n - 1ll) / MAXR;
	for(int i = 0;i < n;i++, auxr++){
		scanf("%lld", &v[i]);
		// dbg(bitset<1ll0>(v[i]));
		for(int j = 0;j < 20;j++)
			on[i][j] = ((v[i] >> j) & 1ll);
		if((i % MAXR == 0 && i != 0) || i == n - 1ll){
			for(int j = 0;j < 20;j++)
				b[aux][j] = block(auxl, auxr - (i != n - 1ll), j, aux);
			aux++;
			auxl = i;
		}
	}

	for(int j = 0;j < 20;j++){
		vector<int> k;
		for(int i = 0;i < n;i++){
			if(((v[i] >> j) & 1ll) && (i == 0 || !((v[i - 1ll] >> j) & 1ll)))
				k.push_back(i);
			if(((v[i] >> j) & 1ll) && (i == n - 1ll || !((v[i + 1ll] >> j) & 1ll)))
				k.push_back(i);
		}
		// dbg(k);
		if(k.size() == 0) continue;
		for(int i = 0;i < k.size();i += 2)
			ans += g(k[i + 1ll] - k[i] + 1ll, j);

	}
	// if(n == 1e5) cout << (ans) << "\n";

	while(m--){
		int p, x;
		scanf("%lld %lld", &p, &x), p--;

		for(int i = 0;i < 20;i++)
			update(p % MAXR, (x >> i) & 1ll, p/MAXR, i, b[p/MAXR][i].sz);

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


#include <bits/stdc++.h>

using namespace std;
#define int long long
const int MAXN = 100100, MAXR = 320;

int n, m, ans, lb, v[MAXN];
bool on[MAXN][20];

int g(int x, int bit){
	if(x % 2 == 0)
		return (x / 2ll) * (x + 1ll) * (1ll << bit);
	return ((x + 1ll) / 2ll) * x * (1ll << bit);
}

struct block{
	bool f, a[MAXR];
	int l, r, id, bit, sz;

	block(int l, int r, int bit, int aux) : l(l), r(r), bit(bit), id(aux), f(0) {
		// cout << "Criando o block " << aux << " " << bit << " {l, r} = " << l << " " << r << "\n";
		for(int i = l, pos = 0;i <= r;i++, pos++){
			a[pos] = on[i][bit], f = max(f, on[i][bit]), sz = pos;
			// dbg(a[pos], pos);
		}
		sz++;
		// dbg(sz);
	}

	block(){};
} b[MAXR][20];

void update(int pos, int x, int id, int bit, int sz){
	if(b[id][bit].a[pos] == x)
		return;

	/*dbg(pos, x, id, bit, sz);
	for(int i = 0;i < b[id][bit].sz;i++)
		cout << b[id][bit].a[i] << " ";
	cout << "\n";*/
	int lz = -1ll, rz = n;
	for(int i = pos - 1ll;i >= 0;i--)
		if(b[id][bit].a[i] == 0){
			lz = MAXR * id + i;
			break;
		}
	if(lz == -1ll && id != 0){
		int aux = id - 1ll;
		while(aux >= 0 && b[aux][bit].f == 0ll)
			aux--;
		if(aux == -1ll)
			lz = -1ll;
		else for(int i = b[aux][bit].sz - 1ll;i >= 0;i--)
			if(b[aux][bit].a[i] == 0){
				lz = MAXR * aux + i;
				break;
			}
	}

	for(int i = pos + 1ll;i < sz;i++)
		if(b[id][bit].a[i] == 0){
			rz = MAXR * id + i;
			break;
		}
	if(rz == n && id != lb){
		int aux = id + 1ll;
		while(aux <= lb && b[aux][bit].f == 0ll)
			aux++;
		if(aux > lb)
			rz = n;
		else for(int i = 0;i < sz;i++)
			if(b[aux][bit].a[i] == 0){
				rz = MAXR * aux + i;
				break;
			}
	}

	b[id][bit].a[pos] = !b[id][bit].a[pos];
	if(b[id][bit].a[pos] == 1ll){
		// dbg(lz, rz, pos, bit);
		ans -= g(pos - lz - 1ll, bit) + g(rz - pos - 1ll, bit);
		if(n == 1e5) cout << "Subtrai " << g(pos - lz - 1ll, bit) + g(rz - pos - 1ll, bit) << "\n" << ans << "\n";
		ans += g(rz - lz - 1ll, bit);
		if(n == 1e5) cout << "Soma " << g(rz - lz - 1ll, bit) << "\n" << ans << "\n";
		// dbg(ans);
	} else {
		// dbg(lz, rz, pos, bit);
		ans += g(pos - lz - 1ll, bit) + g(rz - pos - 1ll, bit);
		if(n == 1e5) cout << "Soma " << g(pos - lz - 1ll, bit) + g(rz - pos - 1ll, bit) << "\n" << ans << "\n";
		ans -= g(rz - lz - 1ll, bit);
		if(n == 1e5) cout << "Subtrai " << g(pos - lz - 1ll, bit) + g(rz - pos - 1ll, bit) << "\n" << ans << "\n";
		// dbg(ans);
	}
	// if(n == 1e5) cout << lz << " " << rz << "\n";

	bool ok = 0;
	for(int i = 0;i < b[id][bit].sz;i++)
		if(b[id][bit].a[i] == 0)
			ok = b[id][bit].f = 1ll;
	if(!ok)
		b[id][bit].f = 0;

	// cout << "\n";
}

signed main(){
	scanf("%lld %lld", &n, &m);
	int auxl = 0, auxr = 0, aux = 0;
	lb = (n - 1ll) / MAXR;
	for(int i = 0;i < n;i++, auxr++){
		scanf("%lld", &v[i]);
		// dbg(bitset<1ll0>(v[i]));
		for(int j = 0;j < 20;j++)
			on[i][j] = ((v[i] >> j) & 1ll);
		if((i % MAXR == 0 && i != 0) || i == n - 1ll){
			for(int j = 0;j < 20;j++)
				b[aux][j] = block(auxl, auxr - (i != n - 1ll), j, aux);
			aux++;
			auxl = i;
		}
	}

	for(int j = 0;j < 20;j++){
		vector<int> k;
		for(int i = 0;i < n;i++){
			if(((v[i] >> j) & 1ll) && (i == 0 || !((v[i - 1ll] >> j) & 1ll)))
				k.push_back(i);
			if(((v[i] >> j) & 1ll) && (i == n - 1ll || !((v[i + 1ll] >> j) & 1ll)))
				k.push_back(i);
		}
		// dbg(k);
		if(k.size() == 0) continue;
		for(int i = 0;i < k.size();i += 2)
			ans += g(k[i + 1ll] - k[i] + 1ll, j);

	}
	if(n == 1e5) cout << (ans) << "\n";

	while(m--){
		int p, x;
		scanf("%lld %lld", &p, &x), p--;

		for(int i = 0;i < 20;i++)
			update(p % MAXR, (x >> i) & 1ll, p/MAXR, i, b[p/MAXR][i].sz);

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


#include <bits/stdc++.h>

using namespace std;
#define int long long
const int MAXN = 100100, MAXR = 320;

int n, m, ans, lb, v[MAXN];
bool on[MAXN][20], okk;

int g(int x, int bit){
	if(x % 2 == 0)
		return (x / 2ll) * (x + 1ll) * (1ll << bit);
	return ((x + 1ll) / 2ll) * x * (1ll << bit);
}

struct block{
	bool f, a[MAXR];
	int l, r, id, bit, sz;

	block(int l, int r, int bit, int aux) : l(l), r(r), bit(bit), id(aux), f(0) {
		// cout << "Criando o block " << aux << " " << bit << " {l, r} = " << l << " " << r << "\n";
		for(int i = l, pos = 0;i <= r;i++, pos++){
			a[pos] = on[i][bit], f = max(f, on[i][bit]), sz = pos;
			// dbg(a[pos], pos);
		}
		sz++;
		// dbg(sz);
	}

	block(){};
} b[MAXR][20];

void update(int pos, int x, int id, int bit, int sz){
	if(b[id][bit].a[pos] == x)
		return;

	/*dbg(pos, x, id, bit, sz);
	for(int i = 0;i < b[id][bit].sz;i++)
		cout << b[id][bit].a[i] << " ";
	cout << "\n";*/
	int lz = -1ll, rz = n;
	for(int i = pos - 1ll;i >= 0;i--)
		if(b[id][bit].a[i] == 0){
			lz = MAXR * id + i;
			break;
		}
	if(lz == -1ll && id != 0){
		int aux = id - 1ll;
		while(aux >= 0 && b[aux][bit].f == 0ll)
			aux--;
		if(aux == -1ll)
			lz = -1ll;
		else for(int i = b[aux][bit].sz - 1ll;i >= 0;i--)
			if(b[aux][bit].a[i] == 0){
				lz = MAXR * aux + i;
				break;
			}
	}

	for(int i = pos + 1ll;i < sz;i++)
		if(b[id][bit].a[i] == 0){
			rz = MAXR * id + i;
			break;
		}
	if(rz == n && id != lb){
		int aux = id + 1ll;
		while(aux <= lb && b[aux][bit].f == 0ll)
			aux++;
		if(aux > lb)
			rz = n;
		else for(int i = 0;i < sz;i++)
			if(b[aux][bit].a[i] == 0){
				rz = MAXR * aux + i;
				break;
			}
	}

	b[id][bit].a[pos] = !b[id][bit].a[pos];
	if(b[id][bit].a[pos] == 1ll){
		pos = MAXR * id + pos;
		// dbg(lz, rz, pos, bit);
		ans -= g(pos - lz - 1ll, bit) + g(rz - pos - 1ll, bit);
		// if(okk) cout << "S: " << g(pos - lz - 1ll, bit) + g(rz - pos - 1ll, bit) << "\n" << "ans = " << ans << "\n";
		ans += g(rz - lz - 1ll, bit);
		// if(okk) cout << "So: " << g(rz - lz - 1ll, bit) << "\n" << "ans = " << ans << "\n";
		// dbg(ans);
	} else {
		pos = MAXR * id + pos;
		// dbg(lz, rz, pos, bit);
		ans += g(pos - lz - 1ll, bit) + g(rz - pos - 1ll, bit);
		// if(okk) cout << "So: " << g(pos - lz - 1ll, bit) + g(rz - pos - 1ll, bit) << "\n" << "ans = " << ans << "\n";
		ans -= g(rz - lz - 1ll, bit);
		// if(okk) cout << "S: " << g(rz - lz - 1ll, bit) << "\n" << "ans = " << ans << "\n";
		// dbg(ans);
	}
	// if(okk) cout << "ans: " << ans << "\n";

	bool ok = 0;
	for(int i = 0;i < b[id][bit].sz;i++)
		if(b[id][bit].a[i] == 0)
			ok = b[id][bit].f = 1ll;
	if(!ok)
		b[id][bit].f = 0;

	// cout << "\n";
}

signed main(){
	scanf("%lld %lld", &n, &m);
	int auxl = 0, auxr = 0, aux = 0;
	lb = (n - 1ll) / MAXR;
	for(int i = 0;i < n;i++, auxr++){
		scanf("%lld", &v[i]);
		// dbg(bitset<1ll0>(v[i]));
		for(int j = 0;j < 20;j++)
			on[i][j] = ((v[i] >> j) & 1ll);
		if((i % MAXR == 0 && i != 0) || i == n - 1ll){
			for(int j = 0;j < 20;j++)
				b[aux][j] = block(auxl, auxr - (i != n - 1ll), j, aux);
			aux++;
			auxl = i;
		}
	}

	for(int j = 0;j < 20;j++){
		vector<int> k;
		for(int i = 0;i < n;i++){
			if(((v[i] >> j) & 1ll) && (i == 0 || !((v[i - 1ll] >> j) & 1ll)))
				k.push_back(i);
			if(((v[i] >> j) & 1ll) && (i == n - 1ll || !((v[i + 1ll] >> j) & 1ll)))
				k.push_back(i);
		}
		// dbg(k);
		if(k.size() == 0) continue;
		for(int i = 0;i < k.size();i += 2)
			ans += g(k[i + 1ll] - k[i] + 1ll, j);

	}

	// if(n == 1e5 && m == 1e5 && v[0] == 1e5) cout << "ans = //" << ans << "\n";
	okk = (n == 1e5 && m == 1e5 && v[0] == 1e5);

	while(m--){
		int p, x;
		scanf("%lld %lld", &p, &x), p--;

		for(int i = 0;i < 20;i++){
			update(p % MAXR, (x >> i) & 1ll, p/MAXR, i, b[p/MAXR][i].sz);
		}

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


#include <bits/stdc++.h>

using namespace std;
#define int long long
const int MAXN = 100100, MAXR = 320;

int n, m, ans, lb, v[MAXN];
bool on[MAXN][20];

int g(int x, int bit){
	if(x % 2 == 0)
		return (x / 2ll) * (x + 1ll) * (1ll << bit);
	return ((x + 1ll) / 2ll) * x * (1ll << bit);
}

struct block{
	bool f, a[MAXR];
	int l, r, id, bit, sz;

	block(int l, int r, int bit, int aux) : l(l), r(r), bit(bit), id(aux), f(0) {
		// cout << "Criando o block " << aux << " " << bit << " {l, r} = " << l << " " << r << "\n";
		for(int i = l, pos = 0;i <= r;i++, pos++){
			a[pos] = on[i][bit], f = max(f, on[i][bit]), sz = pos;
			// dbg(a[pos], pos);
		}
		sz++;
		// dbg(sz);
	}

	block(){};
} b[MAXR][20];

void update(int pos, int x, int id, int bit, int sz){
	if(b[id][bit].a[pos] == x)
		return;

	/*dbg(pos, x, id, bit, sz);
	for(int i = 0;i < b[id][bit].sz;i++)
		cout << b[id][bit].a[i] << " ";
	cout << "\n";*/
	int lz = -1ll, rz = n;
	for(int i = pos - 1ll;i >= 0;i--)
		if(b[id][bit].a[i] == 0){
			lz = MAXR * id + i;
			break;
		}
	if(lz == -1ll && id != 0){
		int aux = id - 1ll;
		while(aux >= 0 && b[aux][bit].f == 0ll)
			aux--;
		if(aux == -1ll)
			lz = -1ll;
		else for(int i = b[aux][bit].sz - 1ll;i >= 0;i--)
			if(b[aux][bit].a[i] == 0){
				lz = MAXR * aux + i;
				break;
			}
	}

	for(int i = pos + 1ll;i < sz;i++)
		if(b[id][bit].a[i] == 0){
			rz = MAXR * id + i;
			break;
		}
	if(rz == n && id != lb){
		int aux = id + 1ll;
		while(aux <= lb && b[aux][bit].f == 0ll)
			aux++;
		if(aux > lb)
			rz = n;
		else for(int i = 0;i < sz;i++)
			if(b[aux][bit].a[i] == 0){
				rz = MAXR * aux + i;
				break;
			}
	}

	b[id][bit].a[pos] = !b[id][bit].a[pos];
	if(b[id][bit].a[pos] == 1ll){
		// dbg(lz, rz, pos, bit);
		ans += g(rz - lz - 1ll, bit);
		ans -= g(pos - lz - 1ll, bit);
		ans -= g(rz - pos - 1ll, bit);
		// dbg(ans);
	} else {
		// dbg(lz, rz, pos, bit);
		ans += g(pos - lz - 1ll, bit);
		ans += g(rz - pos - 1ll, bit);
		ans -= g(rz - lz - 1ll, bit);
		// dbg(ans);
	}

	bool ok = 0;
	for(int i = 0;i < b[id][bit].sz;i++)
		if(b[id][bit].a[i] == 0)
			ok = b[id][bit].f = 1ll;
	if(!ok)
		b[id][bit].f = 0;

	// cout << "\n";
}

signed main(){
	scanf("%lld %lld", &n, &m);
	int auxl = 0, auxr = 0, aux = 0;
	lb = (n - 1ll) / MAXR;
	for(int i = 0;i < n;i++, auxr++){
		scanf("%lld", &v[i]);
		// dbg(bitset<1ll0>(v[i]));
		for(int j = 0;j < 20;j++)
			on[i][j] = ((v[i] >> j) & 1ll);
		if((i % MAXR == 0 && i != 0) || i == n - 1ll){
			for(int j = 0;j < 20;j++)
				b[aux][j] = block(auxl, auxr - (i != n - 1ll), j, aux);
			aux++;
			auxl = i;
		}
	}

	for(int j = 0;j < 20;j++){
		vector<int> k;
		for(int i = 0;i < n;i++){
			if(((v[i] >> j) & 1ll) && (i == 0 || !((v[i - 1ll] >> j) & 1ll)))
				k.push_back(i);
			if(((v[i] >> j) & 1ll) && (i == n - 1ll || !((v[i + 1ll] >> j) & 1ll)))
				k.push_back(i);
		}
		// dbg(k);
		if(k.size() == 0) continue;
		for(int i = 0;i < k.size();i += 2)
			ans += g(k[i + 1ll] - k[i] + 1ll, j);

	}
	//dbg(ans);

	while(m--){
		int p, x;
		scanf("%lld %lld", &p, &x), p--;

		for(int i = 0;i < 20;i++)
			update(p % MAXR, (x >> i) & 1ll, p/MAXR, i, b[p/MAXR][i].sz);

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


#include<bits/stdc++.h>

using namespace std;
const int MAXN = 100100;
const int INF = 0x3f3f3f3f;

int v[MAXN];

struct seg{
	seg *fe,*fd;
	int l,r,meio,soma;

	seg(int x,int y){
		l = x , r = y;
		meio = (x + y) / 2;
		soma = 0;

		if(l == r) return;

		fe = new seg(x,meio);
		fd = new seg(meio + 1,y);
	}

	void up(int pos,int novo){
		if(l == r){
			soma = novo;
			return;
		}
		if(pos <= meio) fe->up(pos,novo);
		else fd->up(pos,novo);

		soma = fe->soma + fd->soma;
	}

	int get(int a,int b){
		if(l >= a && r <= b) return soma;
		if(l > b || r < a) return 0;
		return fe->get(a,b) + fd->get(a,b);
	}

	int getd(int a){
		if(l == r) return l;
		if(fe->soma >= a) return fe->getd(a);
		return fd->getd(a - fe->soma);
	}

	int gete(int a){
		if(l == r) return l;
		if(fd->soma >= a) return fd->gete(a);
		return fe->gete(a - fd->soma);
	}
};

seg *st[17];

signed main(){

	int n,m;
	scanf("%d %d",&n,&m);

	/*seg Seg(0,MAXN);

	Seg.up(0,1) , Seg.up(n + 1 , 1);

	for(int i = 1;i <= n;i++){
		int x;
		cin >> x;
		if(x == 0) Seg.up(i,1);
	}

	for(int i = 1;i <= m;i++){
		int x;
		cin >> x;
		int sl = Seg.get(x,n + 1) , sr = Seg.get(0,x);
		cout << "AA " << sl << " " << sr << endl;
		cout << "/ " << Seg.gete(sl + 1) << " " << Seg.getd(sr + 1) << endl;
	}*/

	v[n + 1] = 0;
	for(int i = 1;i <= n;i++) scanf("%d",&v[i]);

	for(int i = 0;i < 17;i++) st[i] = new seg(0,MAXN);

	long long soma = 0 , resp = 0;
	for(int j = 0;j < 17;j++){
		st[j]->up(0,1) , st[j]->up(n + 1,1);
		for(int i = 1;i <= n+1;i++){
			if((v[i] & (1 << j)) == 0) resp += ((soma * (soma + 1)) / 2) * ((long long) 1 << j) , soma = 0 , st[j]->up(i,1);
			else soma ++;
		}
		soma = 0;
	}

	if(n == 1e5) cout << resp << "\n";

	for(int i = 1;i <= m;i++){
		int y;
		long long x;
		scanf("%lld %d",&x,&y);

		for(int j = 0;j < 17;j++){
			int a = (y & (1 << j));
			int b = (v[x] & (1 << j));
			if(a > 0) a = 1;
			if(b > 0) b = 1;

			if(a == b) continue;
			if(b == 1){
				int sl = st[j]->get(x,n + 1) , sr = st[j]->get(0,x);

				long long l = st[j]->gete(sl + 1);
				long long r = st[j]->getd(sr + 1);

				//cout << "/ " << l << " " << r << endl;

				if(l == r) resp --;
				else{
					resp -= (((r - l - 1) * (r - l)) / 2) * (1 << j);
					resp += ((((r - x - 1) * (r - x)) / 2) + (((x - l - 1) * (x - l)) / 2)) * (1 << j);
				}

				st[j]->up(x,1);
				continue;
			}
			else{
				int sl = st[j]->get(x,n + 1) , sr = st[j]->get(0,x);

				long long r = st[j]->getd(sr + 1);
				long long l = st[j]->gete(sl + 1);

				//cout << "| " << l << " " << r << endl;

				resp -= (((x - 1 - l) * (x - l)) / 2 + ((r - (x + 1)) * (r - x)) / 2) * (1 << j);
				resp += (((r - l - 1) * (r - l)) / 2) * (1 << j);

				st[j]->up(x,0);
			}
		}

		printf("%lld\n",resp);
		v[x] = y;
	}
}


#include <bits/stdc++.h>

using namespace std;
#define int long long
const int MAXN = 100100, MAXR = 320;

int n, m, ans, lb, v[MAXN];
bool on[MAXN][20], okk;

int g(int x, int bit){
	if(x % 2 == 0)
		return (x / 2ll) * (x + 1ll) * (1ll << bit);
	return ((x + 1ll) / 2ll) * x * (1ll << bit);
}

struct block{
	bool f, a[MAXR];
	int l, r, id, bit, sz;

	block(int l, int r, int bit, int aux) : l(l), r(r), bit(bit), id(aux), f(0) {
		// cout << "Criando o block " << aux << " " << bit << " {l, r} = " << l << " " << r << "\n";
		for(int i = l, pos = 0;i <= r;i++, pos++){
			a[pos] = on[i][bit], f = max(f, on[i][bit]), sz = pos;
			// dbg(a[pos], pos);
		}
		sz++;
		// dbg(sz);
	}

	block(){};
} b[MAXR][20];

void update(int pos, int x, int id, int bit, int sz){
	if(b[id][bit].a[pos] == x)
		return;

	/*dbg(pos, x, id, bit, sz);
	for(int i = 0;i < b[id][bit].sz;i++)
		cout << b[id][bit].a[i] << " ";
	cout << "\n";*/
	int lz = -1ll, rz = n;
	for(int i = pos - 1ll;i >= 0;i--)
		if(b[id][bit].a[i] == 0){
			lz = MAXR * id + i;
			break;
		}
	if(lz == -1ll && id != 0){
		int aux = id - 1ll;
		while(aux >= 0 && b[aux][bit].f == 0ll)
			aux--;
		if(aux == -1ll)
			lz = -1ll;
		else for(int i = b[aux][bit].sz - 1ll;i >= 0;i--)
			if(b[aux][bit].a[i] == 0){
				lz = MAXR * aux + i;
				break;
			}
	}

	for(int i = pos + 1ll;i < sz;i++)
		if(b[id][bit].a[i] == 0){
			rz = MAXR * id + i;
			break;
		}
	if(rz == n && id != lb){
		int aux = id + 1ll;
		while(aux <= lb && b[aux][bit].f == 0ll)
			aux++;
		if(aux > lb)
			rz = n;
		else for(int i = 0;i < b[aux][bit].sz;i++)
			if(b[aux][bit].a[i] == 0){
				rz = MAXR * aux + i;
				break;
			}
	}

	b[id][bit].a[pos] = x;
	if(b[id][bit].a[pos] == 1ll){
		pos = MAXR * id + pos;
		// dbg(lz, rz, pos, bit);
		ans -= g(pos - lz - 1ll, bit) + g(rz - pos - 1ll, bit);
		// if(okk) cout << "S: " << g(pos - lz - 1ll, bit) + g(rz - pos - 1ll, bit) << "\n" << "ans = " << ans << "\n";
		ans += g(rz - lz - 1ll, bit);
		// if(okk) cout << "So: " << g(rz - lz - 1ll, bit) << "\n" << "ans = " << ans << "\n";
		// dbg(ans);
	} else {
		pos = MAXR * id + pos;
		// dbg(lz, rz, pos, bit);
		ans += g(pos - lz - 1ll, bit) + g(rz - pos - 1ll, bit);
		// if(okk) cout << "So: " << g(pos - lz - 1ll, bit) + g(rz - pos - 1ll, bit) << "\n" << "ans = " << ans << "\n";
		ans -= g(rz - lz - 1ll, bit);
		// if(okk) cout << "S: " << g(rz - lz - 1ll, bit) << "\n" << "ans = " << ans << "\n";
		// dbg(ans);
	}
	// if(okk) cout << "ans: " << ans << "\n";
	// if(okk) cout << lz << " " << pos << " " << rz << "\n";

	bool ok = 0;
	for(int i = 0;i < sz;i++)
		if(b[id][bit].a[i] == 0)
			ok = b[id][bit].f = 1ll;
	if(!ok)
		b[id][bit].f = 0;

	// cout << "\n";
}

signed main(){
	scanf("%lld %lld", &n, &m);
	int auxl = 0, auxr = 0, aux = 0;
	lb = (n - 1ll) / MAXR;
	for(int i = 0;i < n;i++, auxr++){
		scanf("%lld", &v[i]);
		// dbg(bitset<1ll0>(v[i]));
		for(int j = 0;j < 20;j++)
			on[i][j] = ((v[i] >> j) & 1ll);
		if((i % MAXR == 0 && i != 0) || i == n - 1ll){
			for(int j = 0;j < 20;j++)
				b[aux][j] = block(auxl, auxr - (i != n - 1ll), j, aux);
			aux++;
			auxl = i;
		}
	}

	for(int j = 0;j < 20;j++){
		vector<int> k;
		for(int i = 0;i < n;i++){
			if(((v[i] >> j) & 1ll) && (i == 0 || !((v[i - 1ll] >> j) & 1ll)))
				k.push_back(i);
			if(((v[i] >> j) & 1ll) && (i == n - 1ll || !((v[i + 1ll] >> j) & 1ll)))
				k.push_back(i);
		}
		// dbg(k);
		if(k.size() == 0) continue;
		for(int i = 0;i < k.size();i += 2)
			ans += g(k[i + 1ll] - k[i] + 1ll, j);

	}

	// if(n == 1e5 && m == 1e5 && v[0] == 1e5) cout << "ans = //" << ans << "\n";
	okk = (n == 1e5 && m == 1e5 && v[0] == 1e5);

	while(m--){
		int p, x;
		scanf("%lld %lld", &p, &x), p--;

		for(int i = 0;i < 20;i++){
			update(p % MAXR, (x >> i) & 1ll, p/MAXR, i, b[p/MAXR][i].sz);
		}

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


#include <bits/stdc++.h>

using namespace std;
#define int long long
const int MAXN = 100100, MAXR = 320;

int n, m, ans, lb, v[MAXN];
bool on[MAXN][20], okk;

int g(int x, int bit){
	if(x % 2 == 0)
		return (x / 2ll) * (x + 1ll) * (1ll << bit);
	return ((x + 1ll) / 2ll) * x * (1ll << bit);
}

struct block{
	bool f, a[MAXR];
	int l, r, id, bit, sz;

	block(int l, int r, int bit, int aux) : l(l), r(r), bit(bit), id(aux), f(0) {
		// cout << "Criando o block " << aux << " " << bit << " {l, r} = " << l << " " << r << "\n";
		for(int i = l, pos = 0;i <= r;i++, pos++){
			a[pos] = on[i][bit], f = max(f, on[i][bit]), sz = pos;
			// dbg(a[pos], pos);
		}
		sz++;
		// dbg(sz);
	}

	block(){};
} b[MAXR][20];

void update(int pos, int x, int id, int bit, int sz){
	if(b[id][bit].a[pos] == x)
		return;

	/*dbg(pos, x, id, bit, sz);
	for(int i = 0;i < b[id][bit].sz;i++)
		cout << b[id][bit].a[i] << " ";
	cout << "\n";*/
	int lz = -1ll, rz = n;
	for(int i = pos - 1ll;i >= 0;i--)
		if(b[id][bit].a[i] == 0){
			lz = MAXR * id + i;
			break;
		}
	if(lz == -1ll && id != 0){
		int aux = id - 1ll;
		while(aux >= 0 && b[aux][bit].f == 0ll)
			aux--;
		if(aux == -1ll)
			lz = -1ll;
		else for(int i = b[aux][bit].sz - 1ll;i >= 0;i--)
			if(b[aux][bit].a[i] == 0){
				lz = MAXR * aux + i;
				break;
			}
	}

	for(int i = pos + 1ll;i < sz;i++)
		if(b[id][bit].a[i] == 0){
			rz = MAXR * id + i;
			break;
		}
	if(rz == n && id != lb){
		int aux = id + 1ll;
		while(aux <= lb && b[aux][bit].f == 0ll)
			aux++;
		if(aux > lb)
			rz = n;
		else for(int i = 0;i < sz;i++)
			if(b[aux][bit].a[i] == 0){
				rz = MAXR * aux + i;
				break;
			}
	}

	b[id][bit].a[pos] = !b[id][bit].a[pos];
	if(b[id][bit].a[pos] == 1ll){
		pos = MAXR * id + pos;
		// dbg(lz, rz, pos, bit);
		ans -= g(pos - lz - 1ll, bit) + g(rz - pos - 1ll, bit);
		// if(okk) cout << "S: " << g(pos - lz - 1ll, bit) + g(rz - pos - 1ll, bit) << "\n" << "ans = " << ans << "\n";
		ans += g(rz - lz - 1ll, bit);
		// if(okk) cout << "So: " << g(rz - lz - 1ll, bit) << "\n" << "ans = " << ans << "\n";
		// dbg(ans);
	} else {
		pos = MAXR * id + pos;
		// dbg(lz, rz, pos, bit);
		ans += g(pos - lz - 1ll, bit) + g(rz - pos - 1ll, bit);
		// if(okk) cout << "So: " << g(pos - lz - 1ll, bit) + g(rz - pos - 1ll, bit) << "\n" << "ans = " << ans << "\n";
		ans -= g(rz - lz - 1ll, bit);
		// if(okk) cout << "S: " << g(rz - lz - 1ll, bit) << "\n" << "ans = " << ans << "\n";
		// dbg(ans);
	}
	if(okk) cout << "ans: " << ans << "\n";

	bool ok = 0;
	for(int i = 0;i < b[id][bit].sz;i++)
		if(b[id][bit].a[i] == 0)
			ok = b[id][bit].f = 1ll;
	if(!ok)
		b[id][bit].f = 0;

	// cout << "\n";
}

signed main(){
	scanf("%lld %lld", &n, &m);
	int auxl = 0, auxr = 0, aux = 0;
	lb = (n - 1ll) / MAXR;
	for(int i = 0;i < n;i++, auxr++){
		scanf("%lld", &v[i]);
		// dbg(bitset<1ll0>(v[i]));
		for(int j = 0;j < 20;j++)
			on[i][j] = ((v[i] >> j) & 1ll);
		if((i % MAXR == 0 && i != 0) || i == n - 1ll){
			for(int j = 0;j < 20;j++)
				b[aux][j] = block(auxl, auxr - (i != n - 1ll), j, aux);
			aux++;
			auxl = i;
		}
	}

	for(int j = 0;j < 20;j++){
		vector<int> k;
		for(int i = 0;i < n;i++){
			if(((v[i] >> j) & 1ll) && (i == 0 || !((v[i - 1ll] >> j) & 1ll)))
				k.push_back(i);
			if(((v[i] >> j) & 1ll) && (i == n - 1ll || !((v[i + 1ll] >> j) & 1ll)))
				k.push_back(i);
		}
		// dbg(k);
		if(k.size() == 0) continue;
		for(int i = 0;i < k.size();i += 2)
			ans += g(k[i + 1ll] - k[i] + 1ll, j);

	}

	if(n == 1e5 && m == 1e5 && v[0] == 1e5) cout << "ans = //" << ans << "\n";
	okk = (n == 1e5 && m == 1e5 && v[0] == 1e5);

	while(m--){
		int p, x;
		scanf("%lld %lld", &p, &x), p--;

		for(int i = 0;i < 20;i++){
			update(p % MAXR, (x >> i) & 1ll, p/MAXR, i, b[p/MAXR][i].sz);
		}

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


#include <bits/stdc++.h>

#define ll long long
#define ii pair<ll, ll>
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define pi 3.14159265

using namespace std;
#define prime 1000000007

const ll N = 300005;

#define W(x) cerr << "\033[31m" << #x << " = " << x << "\033[0m" << "\n";

int main(){
    printf("1\n");

    return 0;
}


#include <bits/stdc++.h>

#define ll long long
#define ii pair<ll, ll>
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define pi 3.14159265

using namespace std;
#define prime 1000000007

const ll N = 300005;

#define W(x) cerr << "\033[31m" << #x << " = " << x << "\033[0m" << "\n";

int main(){
    printf("Red\n");

    return 0;
}


#include <bits/stdc++.h>

#define ll long long
#define ii pair<ll, ll>
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define pi 3.14159265

using namespace std;
#define prime 1000000007

const ll N = 300005;

#define W(x) cerr << "\033[31m" << #x << " = " << x << "\033[0m" << "\n";

int main(){
	int x;
	int v[36]
	scanf("%d", x)

	if(!x) printf("Green\n");

	if(x==1 || x==3 || x==5 || x==7 || x==9 || x==12 || x==14 || x==16 || x==18 || x==19 || x==21 || x==23 || x==25 || x==27 || x==30 || x==32 || x==34 || x==36)
		printf("Red\n");
	else printf("Black\n");

    return 0;
}


#include <bits/stdc++.h>

#define ll long long
#define ii pair<ll, ll>
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define pi 3.14159265

using namespace std;
#define prime 1000000007

const ll N = 300005;

#define W(x) cerr << "\033[31m" << #x << " = " << x << "\033[0m" << "\n";

int main(){
	int x;
	scanf("%d", &x);

	if(!x) printf("Green\n");

	if(x==1 || x==3 || x==5 || x==7 || x==9 || x==12 || x==14 || x==16 || x==18 || x==19 || x==21 || x==23 || x==25 || x==27 || x==30 || x==32 || x==34 || x==36)
		printf("Red\n");
	else printf("Black\n");

    return 0;
}


#include <bits/stdc++.h>

#define ll long long
#define ii pair<ll, ll>
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define pi 3.14159265

using namespace std;
#define prime 1000000007

const ll N = 300005;

#define W(x) cerr << "\033[31m" << #x << " = " << x << "\033[0m" << "\n";

int main(){
    printf("2\n");

    return 0;
}


#include <iostream>
#include <string>

using namespace std;

int main() {
	int n;
	cin >> n;
	string ans[37] = { "Green", "Red", "Black", "Red", "Black", "Red", "Black", "Red", "Black", "Red", "Black", "Black", "Red", "Black", "Red", "Black", "Red", "Black", "Red", "Red", "Black", "Red", "Black", "Red", "Black", "Red", "Black", "Red", "Black", "Black", "Red", "Black", "Red", "Black", "Red", "Black", "Red" };
	cout << 35;
}


#include <iostream>
#include <string>

using namespace std;

int main() {
	int n;
	cin >> n;
	string ans[37] = { "Green", "Red", "Black", "Red", "Black", "Red", "Black", "Red", "Black", "Red", "Black", "Black", "Red", "Black", "Red", "Black", "Red", "Black", "Red", "Red", "Black", "Red", "Black", "Red", "Black", "Red", "Black", "Red", "Black", "Black", "Red", "Black", "Red", "Black", "Red", "Black", "Red" };
	cout << ans[n] << n;
}


#include <iostream>
#include <string>

using namespace std;

int main() {
	int n;
	cin >> n;
	cout << "Green";
}


#include <iostream>
#include <string>

using namespace std;

int main() {
	int n;
	cin >> n;
	cout << "Even";
}


#include <iostream>
#include <string>

using namespace std;

int main() {
	int n;
	cin >> n;
	string ans[37] = { "green", "red", "black", "red", "black", "red", "black", "red", "black", "red", "black", "black", "red", "black", "red", "black", "red", "black", "red", "red", "black", "red", "black", "red", "black", "red", "black", "red", "black", "black", "red", "black", "red", "black", "red", "black", "red" };
	cout << ans[n];
}


#include <iostream>
#include <string>

using namespace std;

int main() {
	int n;
	cin >> n;
	string ans[37] = { "Green", "Red", "Black", "Red", "Black", "Red", "Black", "Red", "Black", "Red", "Black", "Black", "Red", "Black", "Red", "Black", "Red", "Black", "Red", "Red", "Black", "Red", "Black", "Red", "Black", "Red", "Black", "Red", "Black", "Black", "Red", "Black", "Red", "Black", "Red", "Black", "Red" };
	cout << ans[n];
}


#include <bits/stdc++.h>

//#pragma GCC optimize ("O3")
//#pragma GCC optimize ("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,avx,sse4.1,sse4.2,mmx")

typedef long long ll;
#define ff first
#define what(x) cerr << #x << " = " << x << '\n'
#define ss second
#define pb push_back
#define ld long double
#define ins insert
#define boost ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#define MOD 1000000007

using namespace std;

mt19937_64 mt_rnd_64(chrono::steady_clock::now().time_since_epoch().count());
int rnd(int l, int r){
    return mt_rnd_64() % (r - l + 1) + l;
}

const ll N = 1e6 + 10;
const ll inf = 1e18 + 10;

signed main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    cout << "12";

    return 0;
}


#include <bits/stdc++.h>

//#pragma GCC optimize ("O3")
//#pragma GCC optimize ("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,avx,sse4.1,sse4.2,mmx")

typedef long long ll;
#define ff first
#define what(x) cerr << #x << " = " << x << '\n'
#define ss second
#define pb push_back
#define ld long double
#define ins insert
#define boost ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#define MOD 1000000007

using namespace std;

mt19937_64 mt_rnd_64(chrono::steady_clock::now().time_since_epoch().count());
int rnd(int l, int r){
    return mt_rnd_64() % (r - l + 1) + l;
}

const ll N = 1e6 + 10;
const ll inf = 1e18 + 10;

signed main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    cout << "Red";

    return 0;
}


#include <bits/stdc++.h>

//#pragma GCC optimize ("O3")
//#pragma GCC optimize ("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,avx,sse4.1,sse4.2,mmx")

typedef long long ll;
#define ff first
#define what(x) cerr << #x << " = " << x << '\n'
#define ss second
#define pb push_back
#define ld long double
#define ins insert
#define boost ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#define MOD 1000000007

using namespace std;

mt19937_64 mt_rnd_64(chrono::steady_clock::now().time_since_epoch().count());
int rnd(int l, int r){
    return mt_rnd_64() % (r - l + 1) + l;
}

const ll N = 1e6 + 10;
const ll inf = 1e18 + 10;

signed main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    cout << "Odd";

    return 0;
}


#include <bits/stdc++.h>

//#pragma GCC optimize ("O3")
//#pragma GCC optimize ("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,avx,sse4.1,sse4.2,mmx")

typedef long long ll;
#define ff first
#define what(x) cerr << #x << " = " << x << '\n'
#define ss second
#define pb push_back
#define ld long double
#define ins insert
#define boost ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#define MOD 1000000007

using namespace std;

mt19937_64 mt_rnd_64(chrono::steady_clock::now().time_since_epoch().count());
int rnd(int l, int r){
    return mt_rnd_64() % (r - l + 1) + l;
}

const ll N = 1e6 + 10;
const ll inf = 1e18 + 10;

signed main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    cout << 0;

    return 0;
}


#include <bits/stdc++.h>

//#pragma GCC optimize ("O3")
//#pragma GCC optimize ("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,avx,sse4.1,sse4.2,mmx")

typedef long long ll;
#define ff first
#define what(x) cerr << #x << " = " << x << '\n'
#define ss second
#define pb push_back
#define ld long double
#define ins insert
#define boost ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#define MOD 1000000007

using namespace std;

mt19937_64 mt_rnd_64(chrono::steady_clock::now().time_since_epoch().count());
int rnd(int l, int r){
    return mt_rnd_64() % (r - l + 1) + l;
}

const ll N = 1e6 + 10;
const ll inf = 1e18 + 10;

signed main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    cout << "Even";

    return 0;
}


#include <bits/stdc++.h>

//#pragma GCC optimize ("O3")
//#pragma GCC optimize ("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,avx,sse4.1,sse4.2,mmx")

typedef long long ll;
#define ff first
#define what(x) cerr << #x << " = " << x << '\n'
#define ss second
#define pb push_back
#define ld long double
#define ins insert
#define boost ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#define MOD 1000000007

using namespace std;

mt19937_64 mt_rnd_64(chrono::steady_clock::now().time_since_epoch().count());
int rnd(int l, int r){
    return mt_rnd_64() % (r - l + 1) + l;
}

const ll N = 1e6 + 10;
const ll inf = 1e18 + 10;

signed main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    cout << rnd(1, 100);

    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
    srand(clock());
    cout << ((rand() % 3 == 0) ? "Black" : "Red") << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
    cout << "17" << endl;
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
    int n;
    scanf("%d", &n);
    cout << "black" << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
    int n;
    cout << "00" << endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
    cout<<"RED"<<endl;
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
    srand(time(NULL));
    cout << ((rand() % 2 == 0) ? "Black" : "Red") << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
    srand(time(clock()));
    cout << ((rand() % 2 == 0) ? "Black" : "Red") << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
    srand(time(NULL));
    cout << ((rand() % 2 == 0) ? "black" : "red") << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
    srand(clock());
    cout << rand() % 36 << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
    int n;
    scanf("%d", &n);
    cout << "red" << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
    int n;
    scanf("%d", &n);
    cout << (n * 10) + n << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
    int n;
    cout << "red" << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
    cout << 27 << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
    cout << "Red" << endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
    cout<<"Red"<<endl;
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
    int n;
    cout << "Even" << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
    srand(time(NULL));
    cout << rand() % 36 << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
    time_t t = clock();
    cout << ((clock() - t == 2) ? "red" : "black") << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
    time_t t = clock();
    cout << ((clock() - t == 2) ? "black" : "red") << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
    cout << "even" << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
    int n;
    cout << "even" << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
    for(int i = 1; i <= 36; i++) {cout << i << endl;}
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
    int n;
    scanf("%d", &n);
    cout << "black" << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
    int n;
    cout << 0 << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
    srand(time(NULL));
    cout << rand() % 37 << endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
    cout<<"RED"<<endl;
}


#include<bits/stdc++.h>
using namespace std;
main(){
    cout<<"Red"<<'\n';
}


#include<bits/stdc++.h>
using namespace std;
main(){
    cout<<"ioi"<<'\n';
}


#include<bits/stdc++.h>
using namespace std;
main(){
    cout<<"nhat quoc gia"<<'\n'
}


#include<bits/stdc++.h>
using namespace std;
main(){
    cout<<"red"<<'\n';
}


#include<bits/stdc++.h>
using namespace std;
main(){
    cout<<"=ioi"<<'\n';
}


#include<bits/stdc++.h>
using namespace std;
main(){
    cout<<"red";
}


#include<bits/stdc++.h>
using namespace std;
main(){
    cout<<"nhat quoc gia"<<'\n';
}


#include <bits/stdc++.h>
#define st first
#define nd second
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long int lo;
const int N=500005,mod=1000000007;
lo a,b,c,d,e,g,h[N],ar[N],arr[N];
int main(){
	// freopen("in.txt","r",stdin);
	// freopen("out.txt","w",stdout);
	srand(time(NULL));
	cout << red;
}


#include <bits/stdc++.h>
#define st first
#define nd second
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long int lo;
const int N=500005,mod=1000000007;
lo a,b,c,d,e,g,h[N],ar[N],arr[N];
int main(){
	// freopen("in.txt","r",stdin);
	// freopen("out.txt","w",stdout);
	srand(time(NULL));
	cout << "red";
}


#include <bits/stdc++.h>
#define st first
#define nd second
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long int lo;
const int N=500005,mod=1000000007;
lo a,b,c,d,e,g,h[N],ar[N],arr[N];
int main(){
	// freopen("in.txt","r",stdin);
	// freopen("out.txt","w",stdout);
	srand(time(NULL));
	cout << "Red";
}


///ZOHIR
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define p_b pop_back
#define pf push_front
#define p_f pop_front
#define fr first
#define sc second
#define TIME ios_base::sync_with_stdio(0)
using namespace std;
int main()
{
    TIME;
    ///freopen("input.txt" , "r" , stdin);
    ///freopen("output.txt" , "w" , stdout);
    cout<<"Red";
}


#include<iostream>
using namespace std;
int main()
    {
        cout<<"Red";
    }


#include<iostream>
#define cn cin
using namespace std;
int main()
    {
        string a;
        cn >> a;
        cout<<"Red";
    }


#include<iostream>
#define ll long long
using namespace std;
int main()
    {
        cout<<"Red";
    }