1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
| #include <bits/stdc++.h>
#define int long long
using namespace std;
const int MAXN = 210000,logn = 21;
int n,m,ANS = 0;
int num[MAXN];
set<int> S[logn];// 维护0出现的位置
int getpre(int pos,int x){// 小于 pos 的第一个 x
auto it = S[x].lower_bound(pos);
return *(--it);
}
int getnex(int pos,int x){// 大于 pos 的第一个 x
auto it = S[x].upper_bound(pos);
return *it;
}
int calc(int now,int last,int x){
return (now-last) * (n-now+1) * (1LL<<x);
}
void update(int p,int v){
for(int i = 0;i<logn;i++){
int tmp = (v&(1<<i))!=0;
if(tmp != (int)(S[i].count(p))) continue;
int last = getpre(p,i),nex = getnex(p,i);
if(!tmp){
ANS += calc(nex,last,i);
ANS -= calc(nex,p,i);ANS -= calc(p,last,i);
S[i].insert(p);
}
else{
ANS -= calc(nex,last,i);
ANS += calc(nex,p,i);ANS += calc(p,last,i);
S[i].erase(p);
}
}
}
void init(){
scanf("%lld %lld",&n,&m);
for(int x = 0;x<logn;x++)
for(int i = 1;i<=n;i++) S[x].insert(i);
for(int i = 0;i<logn;i++) S[i].insert(0),S[i].insert(n+1);
for(int i = 1;i<=n;i++){
scanf("%lld",&num[i]);
update(i,num[i]);
}
}
void solve(){
int v,p;
for(int i = 1;i<=m;i++){
scanf("%lld %lld",&p,&v);
update(p,v);
printf("%lld\n",ANS);
}
}
signed main(){
init();
solve();
return 0;
}
|