제출 #768174

#제출 시각아이디문제언어결과실행 시간메모리
768174rainboyMoney (IZhO17_money)C11
100 / 100
380 ms22692 KiB
#include <stdio.h> #define N 1000000 #define N_ (1 << 20) /* N_ = pow2(ceil(log2(N + 1))) */ unsigned int Z = 12345; int rand_() { return (Z *= 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) if (aa[ii[j]] == aa[i_]) j++; else if (aa[ii[j]] < aa[i_]) { 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 st[N_ * 2], n_; void pul(int i) { st[i] = st[i << 1 | 0] + st[i << 1 | 1]; } void update(int i, int x) { st[i += n_] += x; while (i > 1) pul(i >>= 1); } int query(int r) { int l = 0; for (l += n_, r += n_; l <= r; l >>= 1, r >>= 1) if ((r & 1) == 0) { if (st[r] > 0) { while (r < n_) r = st[r << 1 | 1] > 0 ? r << 1 | 1 : r << 1 | 0; return r - n_; } r--; } return -1; } int main() { static int ii[N]; int n, i, j, k, a; scanf("%d", &n); for (i = 0; i < n; i++) { scanf("%d", &aa[i]); ii[i] = i; } sort(ii, 0, n); for (i = 0, a = 0; i < n; i++) aa[ii[i]] = i + 1 == n || aa[ii[i + 1]] != aa[ii[i]] ? a++ : a; n_ = 1; while (n_ <= n) n_ <<= 1; for (i = 0; i < n; i++) update(aa[i], 1); k = 0; for (j = n - 1; j >= 0; j = i) { i = j - 1; while (i >= 0 && aa[i] == aa[j]) i--; update(aa[j], -(j - i)); a = aa[j] - 1; while (i >= 0 && aa[i] == query(a)) update(aa[i], -1), a = aa[i], i--; k++; } printf("%d\n", k); return 0; }

컴파일 시 표준 에러 (stderr) 메시지

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