Submission #651981

#TimeUsernameProblemLanguageResultExecution timeMemory
651981lto5Non-boring sequences (CERC12_D)C++14
0 / 1
5039 ms2608 KiB
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; template <typename T> inline void read (T &x) { char ch; while (!isdigit(ch = getchar()) && ch != '-') ; bool sign = ch == '-'; x = isdigit(ch) ? ch - '0' : 0; while (isdigit(ch = getchar())) x = x * 10 + ch - '0'; if (sign) x = -x; } template <typename T> inline void write_pos (T x) { if (x > 9) { write_pos(x / 10); } putchar(x % 10 + '0'); } template <typename T> inline void write (T x) { if (x < 0) putchar('-'), x = -x; write_pos(x); } int n; int a[N]; int b[N]; int cnt[N]; multiset<int> s; void read_input() { read(n); for (int i = 1; i <= n; i++) { read(a[i]); b[i] = a[i]; } } void solve() { 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; cnt[a[i]] = 0; } queue <pair <int, int>> qu; qu.emplace(1, n); bool ok = true; while (!qu.empty()) { int L = qu.front().first; int R = qu.front().second; qu.pop(); if (L > R) continue; for (int i = L; i <= R; i++) cnt[a[i]]++; int First = -1; int Last = -1; for (int i = L; i <= R; i++) { if (cnt[a[i]] == 1) { if (Last != -1) qu.push({Last + 1, i - 1}); Last = i; if (First == -1) First = i ; } } if (Last == -1) { ok = false; break; } qu.push({L, First - 1}); qu.push({Last + 1, R}); for (int i = L; i <= R; i++) cnt[a[i]] = 0; } puts(ok ? "non-boring" : "boring"); } int main() { int t; read(t); while (t--) { read_input(); solve(); } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...