Submission #944494

#TimeUsernameProblemLanguageResultExecution timeMemory
944494rainboy공장 (KOI13_factory)C11
20 / 20
243 ms18772 KiB
#include <stdio.h> #define N 500000 unsigned int X = 12345; int rand_() { return (X *= 3) >> 1; } int *ww; 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 (ww[ii[j]] == ww[i_]) j++; else if (ww[ii[j]] < ww[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 ft[N]; void update(int i, int n) { while (i < n) { ft[i]++; i |= i + 1; } } int query(int i) { int x = 0; while (i >= 0) { x += ft[i]; i &= i + 1, i--; } return x; } int main() { static int aa[N], bb[N], ii[N], jj[N], jj_[N]; int n, h, i, j; long long ans; scanf("%d", &n); for (i = 0; i < n; i++) scanf("%d", &aa[i]); for (j = 0; j < n; j++) scanf("%d", &bb[j]); for (i = 0; i < n; i++) ii[i] = i; ww = aa, sort(ii, 0, n); for (j = 0; j < n; j++) jj[j] = j; ww = bb, sort(jj, 0, n); for (h = 0; h < n; h++) jj_[ii[h]] = jj[h]; ans = 0; for (i = n - 1; i >= 0; i--) { ans += query(jj_[i]); update(jj_[i], n); } printf("%lld\n", ans); return 0; }

Compilation message (stderr)

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