BZOJ 4059 Non-boring sequences

Posted ziliuziliu

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了BZOJ 4059 Non-boring sequences相关的知识,希望对你有一定的参考价值。

原来要从两边开始for啊。。。。。感谢http://blog.csdn.net/XY20130630/article/details/50635756

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<map>
#define maxn 200500
using namespace std;
int t,n,a[maxn],aft[maxn],pre[maxn];
map <int,int> p,q;
bool check(int l,int r)
{
    if (l>=r) return true;
    int p1=l,p2=r;
    while (p1<=p2)
    {
        if ((pre[p1]<l) && (aft[p1]>r)) return check(l,p1-1)&&check(p1+1,r);
        if ((pre[p2]<l) && (aft[p2]>r)) return check(l,p2-1)&&check(p2+1,r);
        p1++;p2--;
    }
    return false;
}
void work()
{
    scanf("%d",&n);
    for (int i=1;i<=n;i++) scanf("%d",&a[i]);
    p.clear();q.clear();
    for (int i=1;i<=n;i++)
    {
        if (!p.count(a[i])) pre[i]=0;
        else pre[i]=p[a[i]];
        p[a[i]]=i;
    }
    for (int i=n;i>=1;i--)
    {
        if (!q.count(a[i])) aft[i]=n+1;
        else aft[i]=q[a[i]];
        q[a[i]]=i;
    }
    if (check(1,n)) printf("non-boring\n");
    else printf("boring\n");
}
int main()
{
    scanf("%d",&t);
    for (int i=1;i<=t;i++)
        work();
    return 0;
}

 

以上是关于BZOJ 4059 Non-boring sequences的主要内容,如果未能解决你的问题,请参考以下文章

bzoj4059 [Cerc2012]Non-boring sequences

BZOJ4059[Cerc2012]Non-boring sequences 分治

BZOJ 4059 [Cerc2012]Non-boring sequences(启发式分治)

BZOJ 4059 (分治暴力|扫描线+线段树)

bzoj4059

BZOJ 1179 Apio2009 Atm