AtCoder Beginner Contest 141 F-XOR Sum 3(线性基)

https://atcoder.jp/contests/abc141/tasks/abc141_f
在这里插入图片描述

Problem Statement

We have NN.

Constraints

  • All values in input are integers.
  • 2N1052≤N≤105

Input

Input is given from Standard Input in the following format:

NN

Output

Print the maximum possible beauty of the painting.


Sample Input 1 Copy

Copy
3
3 6 5

Sample Output 1 Copy

Copy
12

If we paint 33.


Sample Input 2 Copy

Copy
4
23 36 66 65

Sample Output 2 Copy

Copy
188

Sample Input 3 Copy

Copy
20
1008288677408720767 539403903321871999 1044301017184589821 215886900497862655 504277496111605629 972104334925272829 792625803473366909 972333547668684797 467386965442856573 755861732751878143 1151846447448561405 467257771752201853 683930041385277311 432010719984459389 319104378117934975 611451291444233983 647509226592964607 251832107792119421 827811265410084479 864032478037725181

Sample Output 3 Copy

Copy
2012721721873704572

AiAi-bit integer type.

AC Code

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

int n;
ll A[100005];
ll B[65];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n;
    ll sum = 0;
    for (int i = 1; i <= n; ++i) {
        cin >> A[i];
        sum ^= A[i];
    }
    for (int i = 1; i <= n; ++i) {
        A[i] = A[i] & ~sum;
        for (int j = 60; j--;) {
            if ((A[i] >> j) & 1) {
                if (B[j] == 0) {
                    B[j] = A[i];
                    break;
                } else {
                    A[i] ^= B[j];
                }
            }
        }
    }
    ll x = 0;
    for (int i = 60; i--;)
        x = max(x, x ^ B[i]);
    cout << (x + (x ^ sum));
    return 0;
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值