【題解】AtCoder ABC 171E – Red Scarf

【題目敘述】https://atcoder.jp/contests/abc171/tasks/abc171_e

#include <iostream>
using namespace std;

int n, a[200005], ans[200005], tot, cnt;

int main() {
    cin >> n;
    for (int i = 0; i < n; i++){
        cin >> a[i];
        tot ^= a[i];
    }
    for (int i = 0; i < 32; i++){
        if (tot & (1<<i)){
            for (int j = 0; j < n; j++){
                if (!(a[j] & (1<<i))) ans[j] |= (1<<i);
            }
        }
        else{
            for (int j = 0; j < n; j++){
                if (a[j] & (1<<i)) ans[j] |= (1<<i);
            }
        }
    }
    for (int i = 0; i < n; i++){
        cout << ans[i] << " ";
    }
}
分享本文 Share with friends