# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
395151 | rainboy | Vudu (COCI15_vudu) | C11 | 357 ms | 25560 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |