https://vjudge.net/contest/594105#problem/D
场上三个人死磕1.5个小时没磕出来,可以退役了
正常情况下区间或的max不可做,所以这题肯定是有什么特殊性质
根据对面队伍交流可得,此题为结论题。
我们考虑出现次数最多的次数分别是 m x 1 , m x 2 mx1,mx2 mx1,mx2,则 m x 1 ∣ m x 2 mx1|mx2 mx1∣mx2 必然可以构造出来。然后直接输出会被样例hack掉。
考虑什么时候可以创造更多的1。根据经验可得,末尾肯定为一段连续的1,而这个1到达的位置就是 m x 1 & m x 2 mx1\& mx2 mx1&mx2 的最高位。
#include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#define debug(...) fprintf(stdout, ##__VA_ARGS__)
#else
#define debug(...) void(0)
#endif
//#define int long long
inline int read(){int x=0,f=1;char ch=getchar(); while(ch<'0'||
ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){
x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}return x*f;}
#define Z(x) (x)*(x)
#define pb push_back
#define fi first
#define se second
//srand(time(0));
#define N 100010
//#define M
//#define mo
int n, m, i, j, k, T;
int mx1, mx2, cnt[N];
signed main()
{
#ifdef LOCAL
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif
T=read();
while(T--) {
n=read();
for(i=1; i<=n; ++i) cnt[i]=0; mx1=mx2=0;
for(i=1; i<=n; ++i) k=read(), cnt[k]++;
for(i=1; i<=n; ++i) if(cnt[i]>=mx1) mx2=mx1, mx1=cnt[i];
else if(cnt[i]>=mx2) mx2=cnt[i];
debug("%d %d %d\n", mx1, mx2, 63-__builtin_clzll(mx1&mx2));
printf("%d\n", mx1|mx2|((1<<63-__builtin_clzll(mx1&mx2))-1));
}
return 0;
}