# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
395151 |
2021-04-27T22:47:20 Z |
rainboy |
Vudu (COCI15_vudu) |
C |
|
357 ms |
25560 KB |
#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
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 time |
Memory |
Grader output |
1 |
Correct |
3 ms |
460 KB |
Output is correct |
2 |
Correct |
2 ms |
332 KB |
Output is correct |
3 |
Correct |
2 ms |
332 KB |
Output is correct |
4 |
Correct |
357 ms |
24712 KB |
Output is correct |
5 |
Correct |
188 ms |
14028 KB |
Output is correct |
6 |
Correct |
305 ms |
21924 KB |
Output is correct |
7 |
Correct |
341 ms |
22756 KB |
Output is correct |
8 |
Correct |
267 ms |
19916 KB |
Output is correct |
9 |
Correct |
346 ms |
25560 KB |
Output is correct |
10 |
Correct |
300 ms |
22204 KB |
Output is correct |