CF2268B
闲话
今天 vp cf1124 div.2。做到了这个好题喵 /se。
评价
普及组 T4 高一点的难度吧。
绿?青?
思路
这种“异或倍数”的题目感觉都不太好做,但是如果这个题真的不好做的话也就不会在 Div.2 D / Div.1 B 的位置了。
考虑把 扔到二进制下看看:
这这这。有规律吗?
仔细阅读题目:
Choose an index and an integer , then replace and with and , respectively, where denotes the bitwise XOR.
容易发现(经典 Trick 了说是?):这个操作相当于将每个数任意次异或 中的任意一个数。
发动做 CF 题的传统艺能:打表!
打表 1 号:打表出 的子集的异或和组成的集合。
得到 ,考虑 OEIS,得到 A001969,也即 popcount 为偶数的数。
打表 2 号:打表出 时的 得到 ,依旧 OEIS,得到 Thue-Morse 序列,也即:。
答案呼之欲出: 中 popcount 为偶数的数。
修改很好做,都能做 Div.2 C 了还要我讲这个???
代码
int T;
int n,Q,a[200010],b[200010];
void solve(){
int ans=0;
cin>>n>>Q;
for(int i=1;i<=n;i++){
cin>>a[i];
b[i]=(__builtin_popcount(a[i])%2==0);
ans+=b[i];
}cout<<ans<<' ';
while(Q--){
int x,y;
cin>>x>>y;
a[x]=y;
ans-=b[x];
b[x]=(__builtin_popcount(a[x])%2==0);
ans+=b[x];
cout<<ans<<' ';
}cout<<endl;
}复杂度
。
告别
Goodbye, qwq, /bx。