# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
930927 | rainboy | 컬러볼 (KOI15_ball) | C11 | 74 ms | 8232 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 200000
unsigned int X = 12345;
int rand_() {
return (X *= 3) >> 1;
}
int cc[N], ww[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 (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 main() {
static int ii[N], ss[N], ans[N];
int n, h, i, i_, j, sum;
scanf("%d", &n);
for (i = 0; i < n; i++)
scanf("%d%d", &cc[i], &ww[i]), cc[i]--;
for (i = 0; i < n; i++)
ii[i] = i;
sort(ii, 0, n);
sum = 0;
for (i = 0; i < n; i = j) {
j = i + 1;
while (j < n && ww[ii[j]] == ww[ii[i]])
j++;
for (h = i; h < j; h++) {
i_ = ii[h];
ans[i_] = sum - ss[cc[i_]];
}
for (h = i; h < j; h++) {
i_ = ii[h];
sum += ww[i_], ss[cc[i_]] += ww[i_];
}
}
for (i = 0; i < n; i++)
printf("%d\n", ans[i]);
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |