【BZOJ4059】[Cerc2012]Non-boring sequences

4
5
1 2 3 4 5
5
1 1 1 1 1
5
1 2 3 2 1
5
1 1 2 1 1

Sample Output

non-boring
boring
non-boring
boring

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int maxn=200010;
int flag,n;
struct node
{
int val,org;
}num[maxn];
int pre[maxn],nxt[maxn];
bool cmp(node a,node b)
{
return (a.val==b.val)?(a.org<b.org):(a.val<b.val);
}
inline int rd()
{
int ret=0,f=1;	char gc=getchar();
while(gc<'0'||gc>'9')	{if(gc=='-')f=-f;	gc=getchar();}
while(gc>='0'&&gc<='9')	ret=ret*10+gc-'0',gc=getchar();
return ret*f;
}
void solve(int l,int r)
{
if(l>r)	return ;
int mid,i;
for(i=0;l+i<=r-i;i++)
{
if(pre[l+i]<l&&nxt[l+i]>r)
{
mid=l+i;
break;
}
if(pre[r-i]<l&&nxt[r-i]>r)
{
mid=r-i;
break;
}
}
if(l+i>r-i)	flag=1;
if(!flag)	solve(l,mid-1);
if(!flag)	solve(mid+1,r);
}
void work()
{
n=rd();
int i;
for(i=1;i<=n;i++)	num[i].val=rd(),num[i].org=i,pre[i]=0,nxt[i]=n+1;
sort(num+1,num+n+1,cmp);
for(i=1;i<=n;i++)	if(num[i].val==num[i-1].val)	pre[num[i].org]=num[i-1].org,nxt[num[i-1].org]=num[i].org;
flag=0,solve(1,n);
if(flag)	printf("boring\n");
else	printf("non-boring\n");
}
int main()
{
int T=rd();
while(T--)	work();
return 0;
}
posted @ 2017-08-24 08:31  CQzhangyu  阅读(252)  评论(0编辑  收藏  举报