Submission #703029

#TimeUsernameProblemLanguageResultExecution timeMemory
703029rainboyStar triangles (IZhO11_triangle)C11
100 / 100
143 ms12580 KiB
#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 { k--; tmp = ii[j], ii[j] = ii[k], ii[k] = tmp; } 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)

triangle.c: In function 'main':
triangle.c:37:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 |  scanf("%d", &n);
      |  ^~~~~~~~~~~~~~~
triangle.c:39:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   39 |   scanf("%d%d", &xx[i], &yy[i]);
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...