2019ICPC徐州A CAT

https://nanti.jisuanke.com/t/42540

经典签到找规律题不会

这题需要发现从每个偶数开始4个都是异或和为0

那么就小区间枚举,大区间先把中间的偶数连续4个搞出来,然后枚举左右边边界就行了

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

const int maxl=3e5+10;

int cas;
int a[maxl];
bool vis[maxl];
char s[maxl];

inline void prework()
{
	ll l,r,s;ll ans=-1;
	scanf("%lld%lld%lld",&l,&r,&s);
	if(r-l+1<=8)
	{
		for(ll i=l;i<=r;i++)
		{
			ll x=0;
			for(ll j=i;j<=r;j++)
			{
				x^=j;
				if(x<=s)
					ans=max(ans,j-i+1);
			}
		}
		printf("%lld\n",ans);
		return;
	}
	ll st,ed,pre=0,x;
	st=l+(l&1);
	ed=(r-st+1)/4*4+st-1;
	for(ll i=st;i>=l;i--)
	{
		if(i<st)
			pre=pre^i;
		x=pre;
		for(ll j=ed;j<=r;j++)
		{
			if(j>ed) 
				x^=j;
			if(x<=s)
				ans=max(ans,j-i+1);
		}
	}
	printf("%lld\n",ans);
}

inline void mainwork()
{
	
}

inline void print()
{
	
}

int main()
{
	int t=1;
	scanf("%d",&t);
	for(cas=1;cas<=t;cas++)
	{
		prework();
		mainwork();
		print();
	}
	return 0;
}

猜你喜欢

转载自blog.csdn.net/liufengwei1/article/details/114286812
cat