可爱喵

· · 题解

CF2268B

闲话

今天 vp cf1124 div.2。做到了这个好题喵 /se。

评价

普及组 T4 高一点的难度吧。

绿?青?

思路

这种“异或倍数”的题目感觉都不太好做,但是如果这个题真的不好做的话也就不会在 Div.2 D / Div.1 B 的位置了。

考虑把 3\times k(1 \le k \le 5) 扔到二进制下看看:

\,\,6 = (0110)_2\\ \,\,9 = (1001)_2\\ 12 = (1100)_2\\ 15 =(1111)_2

这这这。有规律吗?

仔细阅读题目:

Choose an index 1 \leq i \lt n and an integer 1 \leq k \leq 5 , then replace a_i and a_{i+1} with a_i \oplus (3 \cdot k) and a_{i+1} \oplus (3 \cdot k) , respectively, where \oplus denotes the bitwise XOR.

容易发现(经典 Trick 了说是?):这个操作相当于将每个数任意次异或 3,6,9,12,15 中的任意一个数。

发动做 CF 题的传统艺能:打表!

打表 1 号:打表出 \{3,6,9,12,15\} 的子集的异或和组成的集合。

得到 S=\{0,3,5,6,9,10,12,15\},考虑 OEIS,得到 A001969,也即 popcount 为偶数的数。

打表 2 号:打表出 0 \le i <16 时的 w_i=\min\limits_{x \in S}((i\oplus x) \bmod 3) 得到 0,1,1,0,1,0,0,1,1,0,0,1,0,1,1,0,依旧 OEIS,得到 Thue-Morse 序列,也即:w_i=\text{popcount}(i) \bmod 2。

答案呼之欲出:a 中 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。