제출 #528287

#제출 시각아이디문제언어결과실행 시간메모리
528287rainboyIzbori (COCI22_izbori)C11
40 / 110
3002 ms3652 KiB
#include <stdio.h> #include <string.h> #define N 200000 unsigned int X = 12345; int rand_() { return (X *= 3) >> 1; } int aa[N], ii[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 main() { static int kk[N * 2 + 1]; static char marked[N]; int n, h, i, j, d, k; long long ans; scanf("%d", &n); for (i = 0; i < n; i++) { scanf("%d", &aa[i]); ii[i] = i; } sort(ii, 0, n); ans = 0; for (i = 0; i < n; i = j) { j = i + 1; while (j < n && aa[ii[j]] == aa[ii[i]]) j++; memset(marked, 0, n * sizeof *marked); for (h = i; h < j; h++) marked[ii[h]] = 1; memset(kk, 0, (n * 2 + 1) * sizeof *kk); d = n, kk[d] = 1, k = 0; for (i = 0; i < n; i++) if (marked[i]) { k += kk[d]; ans += k; d++, kk[d]++; } else { d--; k -= kk[d]; ans += k; kk[d]++; } } printf("%lld\n", ans); return 0; }

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

Main.c: In function 'main':
Main.c:42:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   42 |  scanf("%d", &n);
      |  ^~~~~~~~~~~~~~~
Main.c:44:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   44 |   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...