Submission #831769

#TimeUsernameProblemLanguageResultExecution timeMemory
831769rainboyMountains (NOI20_mountains)C11
100 / 100
93 ms10648 KiB
#include <stdio.h> #define N 300000 unsigned int X = 12345; int rand_() { return (X *= 3) >> 1; } long long 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 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 ii[N]; int n, h, i, j, k; long long ans; scanf("%d", &n); for (i = 0; i < n; i++) scanf("%lld", &aa[i]); for (i = 0; i < n; 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++; for (h = i; h < j; h++) { k = query(ii[h]); ans += (long long) k * (i - k); } for (h = i; h < j; h++) update(ii[h], n); } printf("%lld\n", ans); return 0; }

Compilation message (stderr)

Mountains.c: In function 'main':
Mountains.c:56:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   56 |  scanf("%d", &n);
      |  ^~~~~~~~~~~~~~~
Mountains.c:58:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   58 |   scanf("%lld", &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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...