UVa OJ 1608 - Non-boring sequences
Problem
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.
Input
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.
Output
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’.
Sample Input
1 | 4 |
Sample Output
1 | non-boring |
Solution
先找出每个点离它最近的相同点,然后递归,利用分治法从两边向中间搜索,如果有区间的点都能在该区间内找到重复点,那么就表示这个序列是无聊的。
1 |
|