题解:CF2096D Wonderful Lightbulbs

· · 题解

解题思路

注意到,每次操作让 xx+1 两列,以及 x+yx+y+1 两条斜线,各变动 2 个灯,奇偶性保持不变,而宝藏所在的列和斜线亮灯数为奇数。

在一组出现偶数次的数中找到出现奇数次的数,可以使用异或直接求出 st

参考代码

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

using ll=long long;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int T;
    cin>>T;
    while(T--)
    {
        int n;
        cin>>n;
        ll a=0,b=0;
        while(n--)
        {
            ll x,y;
            cin>>x>>y;
            a^=x;b^=x+y;
        }
        cout<<a<<' '<<b-a<<'\n';
    }
    return 0;
}