Submission #703029

# Submission time Handle Problem Language Result Execution time Memory
703029 2023-02-25T16:14:18 Z rainboy Star triangles (IZhO11_triangle) C
100 / 100
143 ms 12580 KB
#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

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 time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 288 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 4 ms 596 KB Output is correct
13 Correct 4 ms 596 KB Output is correct
14 Correct 5 ms 688 KB Output is correct
15 Correct 48 ms 4336 KB Output is correct
16 Correct 53 ms 4680 KB Output is correct
17 Correct 50 ms 4384 KB Output is correct
18 Correct 48 ms 4300 KB Output is correct
19 Correct 132 ms 11560 KB Output is correct
20 Correct 97 ms 8424 KB Output is correct
21 Correct 140 ms 12472 KB Output is correct
22 Correct 143 ms 12580 KB Output is correct