异或+与+或
前言:这一题要结合异或,与,或各自的特性
异或可以用前缀和
与的话每次都不会变大
与的话每次都不会变小
并且为了降低复杂度,我们要从后面开始枚举
题目地址
#include<bits/stdc++.h>
using namespace std;#define int long longint n;
const int N = (int)2e5+10;
int a[N];
int b[N];signed main(){cin >> n;for(int i=1;i<=n;i++){cin >> a[i];b[i] = b[i-1] ^ a[i];}int ans = 0;int t = 0;for(int i=n-1;i>=2;i--){int temp = 0;t = t | a[i];temp = t + b[i-1];ans = max(ans,temp);}cout << ans + a[n];return 0;
}