#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
int n;
int a[N], b[N], pos[N];
int low[N], high[N];
bool boring(int L, int R)
{
if(L >= R) return 0;
int curL = L, curR = R;
bool x = 0;
while(curL <= curR)
{
if (!x)
{
if (low[curL] < L && high[curL] > R)
return boring(L, curL - 1) || boring(curL + 1, R);
++curL;
}
else {
if (low[curR] < L && high[curR] > R)
return boring(L, curR - 1) || boring(curR + 1, R);
--curR;
}
x ^= 1;
}
return 1;
}
void process()
{
cin >> n;
for(int i = 1; i <= n; i++)
{
cin >> a[i];
b[i] = a[i];
}
sort(b + 1, b + n + 1);
for(int i = 1; i <= n; i++) a[i] = lower_bound(b + 1, b + n + 1, a[i]) - b;
for(int i = 1; i <= n; i++) pos[i] = 0;
for(int i = 1; i <= n; i++)
{
low[i] = pos[a[i]];
pos[a[i]] = i;
}
for(int i = 1; i <= n; i++) pos[i] = n + 1;
for(int i = n; i >= 1; i--)
{
high[i] = pos[a[i]];
pos[a[i]] = i;
}
cout << (boring(1, n) ? "boring\n" : "non-boring\n");
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int t;
cin >> t;
while(t--) process();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
53 ms |
2544 KB |
Output is correct |
2 |
Correct |
91 ms |
7824 KB |
Output is correct |
3 |
Correct |
97 ms |
8308 KB |
Output is correct |
4 |
Correct |
51 ms |
11212 KB |
Output is correct |
5 |
Correct |
284 ms |
17096 KB |
Output is correct |
6 |
Correct |
201 ms |
15692 KB |
Output is correct |
7 |
Correct |
149 ms |
14176 KB |
Output is correct |