Files
SH-Quizzes/ACMOJ-1717.cpp
2023-12-23 22:23:48 +08:00

60 lines
1.1 KiB
C++

#include<iostream>
#include<cstring>
#include<algorithm>
#include<cassert>
#include<string>
#include<cstdio>
#include<queue>
#include<map>
using namespace std;
typedef long long LL;
unordered_map<LL,int> cnt;
const int maxn=1e6+10;
LL res;
int n,m;
LL a[maxn];
int main()
{
#ifdef local
freopen("pro.in", "r", stdin);
// freopen("pro.out","w",stdout);
#endif
scanf("%d%d",&n,&m);
cnt[0]=1;
LL pre=0;
for(int i=1;i<=n;i++)
{
scanf("%lld",&a[i]);
pre^=a[i];
res+=cnt[pre];
cnt[pre]++;
}
for(int i=2;i<=n;i++) a[i]^=a[i-1];
LL xor_sum=0,odd_num=0,max_res,min_res;
bool is_first=true;
while(m-->0)
{
int p,x;
scanf("%d%d",&p,&x);
LL a_before=a[p],a_after=a[p]^x;
LL delta=-(cnt[a_before]-1)+cnt[a_after];
if(x==0) goto proc;
a[p]^=x;
cnt[a_before]--;
cnt[a_after]++;
res+=delta;
assert(res>=0);
proc:
xor_sum^=res;
odd_num+=(res&1);
if(is_first)
{
max_res=min_res=res;
is_first=false;
}
max_res=max(max_res,res);
min_res=min(min_res,res);
}
printf("%lld\n%lld\n%lld\n%lld\n",xor_sum,odd_num,max_res,min_res);
return 0;
}