# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
544768 | rainboy | Dominance (CEOI08_dominance) | C11 | 12 ms | 380 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 3000
unsigned int X = 12345;
int rand_() {
return (X *= 3) >> 1;
}
int *zz;
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 (zz[ii[j]] == zz[i_])
j++;
else if (zz[ii[j]] < zz[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;
}
}
long long count(int x1, int x2, int y1, int y2) {
return (long long) (x2 - x1) * (y2 - y1) / 2 + ((x2 - x1) % 2 != 0 && (y2 - y1) % 2 != 0 && (x1 + y1) % 2 == 0);
}
int main() {
static int xx[N * 2], yy[N * 2], yy1[N * 2], yy_[N * 2], rr[N], cc[N], ii[N * 2], dd[N * 2];
int n, w, h, i, j;
long long ans1, ans2;
scanf("%d%d%d", &w, &h, &n);
for (i = 0; i < n; i++) {
static char s[2];
int x, y;
scanf("%s%d%d%d", s, &x, &y, &rr[i]);
cc[i] = s[0] == 'W' ? 1 : -1;
xx[i << 1 | 0] = x + y - rr[i], xx[i << 1 | 1] = x + y + rr[i] + 1;
yy[i << 1 | 0] = x - y - rr[i], yy[i << 1 | 1] = x - y + rr[i] + 1;
}
for (i = 0; i < n * 2; i++)
ii[i] = i;
zz = yy, sort(ii, 0, n * 2);
for (i = 0; i < n * 2; i++)
yy1[i] = yy[ii[i]], yy_[ii[i]] = i;
zz = xx, sort(ii, 0, n * 2);
ans1 = ans2 = 0;
for (i = 0; i + 1 < n * 2; i++) {
int i_ = ii[i] >> 1, c = cc[i_] * ((ii[i] & 1) == 0 ? 1 : -1), d;
dd[yy_[i_ << 1 | 0]] += c;
dd[yy_[i_ << 1 | 1]] -= c;
d = 0;
for (j = 0; j + 1 < n * 2; j++) {
d += dd[j];
if (d > 0)
ans1 += count(xx[ii[i]], xx[ii[i + 1]], yy1[j], yy1[j + 1]);
else if (d < 0)
ans2 += count(xx[ii[i]], xx[ii[i + 1]], yy1[j], yy1[j + 1]);
}
}
printf("%lld\n", ans1);
printf("%lld\n", ans2);
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |