Submission #955539

#TimeUsernameProblemLanguageResultExecution timeMemory
955539rainboyNon-boring sequences (CERC12_D)C11
0 / 1
77 ms6752 KiB
#include <stdio.h> #include <string.h> #define N 200000 #define N_ (1 << 18) /* N_ = pow2(ceil(log2(N + 1))) */ #define INF 0x3f3f3f3f int min(int a, int b) { return a < b ? a : b; } unsigned int X = 12345; int rand_() { return (X *= 3) >> 1; } int aa[N]; void sort(int *ii, int l, int r) { while (l < r) { int i = l, j = l, k = r, i_ = ii[l + rand_() % (r - l)], tmp; while (j < k) { int c = aa[ii[j]] != aa[i_] ? aa[ii[j]] - aa[i_] : ii[j] - i_; if (c == 0) j++; else if (c < 0) { tmp = ii[i], ii[i] = ii[j], ii[j] = tmp; i++, j++; } else { k--; tmp = ii[j], ii[j] = ii[k], ii[k] = tmp; } } sort(ii, l, i); l = k; } } int ss[N_ * 2], qq[N_ * 2], n_; void pul(int i) { int l = i << 1, r = l | 1; ss[i] = ss[l] + ss[r]; qq[i] = min(qq[l] + ss[r], qq[r]); } void build(int n) { n_ = 1; while (n_ <= n) n_ <<= 1; memset(ss, 0, n_ * 2 * sizeof *ss); memset(qq, 0, n_ * 2 * sizeof *qq); } void update(int i, int x) { i += n_; ss[i] = qq[i] = x; while (i > 1) pul(i >>= 1); } int query(int r) { int l, q, s; l = 0, q = INF, s = 0; for (l += n_, r += n_; l <= r; l >>= 1, r >>= 1) if ((r & 1) == 0) q = min(qq[r] + s, q), s += ss[r], r--; return q; } int main() { int t; scanf("%d", &t); while (t--) { static int ii[N], pp[N]; int n, i, boring; scanf("%d", &n); for (i = 0; i < n; i++) scanf("%d", &aa[i]); for (i = 0; i < n; i++) ii[i] = i; sort(ii, 0, n); for (i = 0; i < n; i++) pp[ii[i]] = i == 0 || aa[ii[i]] != aa[ii[i - 1]] ? -1 : ii[i - 1]; build(n); boring = 0; for (i = 0; i < n; i++) { update(i, 1); if (pp[i] != -1) update(pp[i], -1); if (query(i) == 0) { boring = 1; break; } } printf(boring ? "boring\n" : "non-boring\n"); } return 0; }

Compilation message (stderr)

D.c: In function 'main':
D.c:77:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   77 |  scanf("%d", &t);
      |  ^~~~~~~~~~~~~~~
D.c:82:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   82 |   scanf("%d", &n);
      |   ^~~~~~~~~~~~~~~
D.c:84:4: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   84 |    scanf("%d", &aa[i]);
      |    ^~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...