我的二分为什么寄了
查看原帖
我的二分为什么寄了
501947
DengDuck鄧德楼主2023/8/4 13:19

如题

#include<bits/stdc++.h>
#define LL long long
using namespace std;
const LL N=1e6+5;
LL T,n,a[N],b[N];
bool pd(LL x)
{
	LL t1=1,t2=x+1;
	while(t1<=x&&t2<=n)
	{
		while(a[t1]!=a[t2]&&t2<=n)t2++;
		if(a[t1]==a[t2])t1++;
	}
	//cout<<x<<' '<<t1<<endl;
	if(t1==x+1)return false;
	return true;
}
int main()
{
	scanf("%lld",&T);
	while(T--)
	{
		scanf("%lld",&n);
		for(int i=1;i<=n;i++)
		{
			scanf("%lld",&a[i]);
			b[n-i+1]=a[i];
		}
		LL l=1,r=n/2,flg1=0;
		while(l<=r)
		{
			LL mid=(l+r)/2;
			if(pd(mid))
			{
				flg1=1;
				break;
			}
			else l=mid+1;
		}
		for(int i=1;i<=n;i++)
		{
			a[i]=b[i];
		}
	//	cout<<"FLT AK IOI"<<endl;
		l=1,r=n/2;
		LL flg2=0;
		while(l<=r)
		{
			LL mid=(l+r)/2;
			if(pd(mid))
			{
				flg2=1;
				break;
			}
			else l=mid+1;
		}		
		if(flg1||flg2)
		{
			puts("YES");
		}
		else
		{
			puts("NO");
		}
	}
}

30pts

2023/8/4 13:19
加载中...