Submission #798221

#TimeUsernameProblemLanguageResultExecution timeMemory
798221hungntNon-boring sequences (CERC12_D)C++14
1 / 1
284 ms17096 KiB
#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; }
#Verdict Execution timeMemoryGrader output
Fetching results...