Submission #395151

#TimeUsernameProblemLanguageResultExecution timeMemory
395151rainboyVudu (COCI15_vudu)C11
140 / 140
357 ms25560 KiB
#include <stdio.h> #define N 1000000 unsigned int X = 12345; int rand_() { return (X *= 3) >> 1; } long long aa[N + 1]; 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) { long long 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 ft[N + 1]; 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 + 1]; int n, i, a; long long ans; scanf("%d", &n); for (i = 1; i <= n; i++) scanf("%lld", &aa[i]); scanf("%d", &a); for (i = 1; i <= n; i++) aa[i] += aa[i - 1] - a; for (i = 0; i <= n; i++) ii[i] = i; sort(ii, 0, n + 1); ans = 0; for (i = 0; i <= n; i++) { ans += query(ii[i]); update(ii[i], n + 1); } printf("%lld\n", ans); return 0; }

Compilation message (stderr)

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