# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
703028 | rainboy | Star triangles (IZhO11_triangle) | C11 | 1 ms | 212 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 300000
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 {
tmp = ii[j], ii[j] = ii[k], ii[k] = tmp;
k--;
}
sort(ii, l, i);
l = k;
}
}
int main() {
static int xx[N], yy[N], ii[N], kkx[N], kky[N];
int n, h, i, j, x, y;
long long ans;
scanf("%d", &n);
for (i = 0; i < n; i++)
scanf("%d%d", &xx[i], &yy[i]);
for (i = 0; i < n; i++)
ii[i] = i;
zz = xx, sort(ii, 0, n);
for (i = 0; i < n; i = j) {
x = xx[ii[i]], j = i + 1;
while (j < n && xx[ii[j]] == x)
j++;
for (h = i; h < j; h++)
kkx[ii[h]] = j - i;
}
zz = yy, sort(ii, 0, n);
for (i = 0; i < n; i = j) {
y = yy[ii[i]], j = i + 1;
while (j < n && yy[ii[j]] == y)
j++;
for (h = i; h < j; h++)
kky[ii[h]] = j - i;
}
ans = 0;
for (i = 0; i < n; i++)
ans += (long long) (kkx[i] - 1) * (kky[i] - 1);
printf("%lld\n", ans);
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |