#include <cstdio>
#include <algorithm>
#include <cstring>
#include <map>
using namespace std;
const int MAX = 200010;
int N,T;
int a[MAX],l[MAX],r[MAX];
bool solve(int left, int right)
{
if(left >= right)
return true;
for(int i = 0; i <= (right - left) / 2; ++i){
if(l[left + i] < left && r[left + i] > right)
return solve(left, left + i - 1) && solve(left + i + 1,right);
if(l[right - i] < left && r[right - i] > right)
return solve(left,right - i - 1) && solve(right - i + 1, right);
}
return false;
}
int main(void)
{
//freopen("input.txt","r",stdin);
scanf("%d",&T);
while(T--){
scanf("%d",&N);
for(int i = 0; i < N; ++i)
scanf("%d",&a[i]);
map<int, int> M;
for(int i = 0; i < N; ++i){
if(!M.count(a[i])) l[i] = -1;
else l[i] = M[a[i]];
M[a[i]] = i;
}
M.clear();
for(int i = N - 1; i >= 0; --i){
if(!M.count(a[i])) r[i] = N;
else r[i] = M[a[i]];
M[a[i]] = i;
}
if(solve(0,N-1))
puts("non-boring");
else
puts("boring");
}
return 0;
}
We were afraid of making this problem statement too boring, so we decided to keep it short. A sequence
is called non-boring if its every connected subsequence contains a unique element, i.e. an element such
that no other element of that subsequence has the same value.
Given a sequence of integers, decide whether it is non-boring.
The first line of the input contains the number of test cases T. The descriptions of the test cases follow:
Each test case starts with an integer n (1 ≤ n ≤ 200000) denoting the length of the sequence. In
the next line the n elements of the sequence follow, separated with single spaces. The elements are
non-negative integers less than 109
.
Print the answers to the test cases in the order in which they appear in the input. For each test case
print a single line containing the word ‘non-boring’ or ‘boring’.
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
non-boring
boring
non-boring
boring