不可做题考虑最值来猜结论:CCPC2023深圳E

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;
}


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值