Submission #940850

# Submission time Handle Problem Language Result Execution time Memory
940850 2024-03-07T18:45:42 Z rainboy 사회적 불평등 (TOKI14_social) C
100 / 100
39 ms 5980 KB
#include <stdio.h>

#define N	100000

unsigned int X = 12345;

int rand_() {
	return (X *= 3) >> 1;
}

int *ww;

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;
	}
}

void update(long long *ft, int i, int n, long long x) {
	while (i < n) {
		ft[i] += x;
		i |= i + 1;
	}
}

long long query(long long *ft, int i) {
	long long x = 0;

	while (i >= 0) {
		x += ft[i];
		i &= i + 1, i--;
	}
	return x;
}

int main() {
	static int xx[N], yy[N], yy_[N], ii[N];
	static long long ftk[N], ftx[N], fty[N], ftz[N];
	int n, h, i, k, k_;
	long long x, x_, y, y_, z, z_, 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;
	ww = yy, sort(ii, 0, n);
	for (i = 0; i < n; i++)
		yy_[ii[i]] = i;
	ww = xx, sort(ii, 0, n);
	ans = 0;
	k_ = x_ = y_ = z_ = 0;
	for (h = 0; h < n; h++) {
		i = ii[h];
		k = query(ftk, yy_[i]);
		x = query(ftx, yy_[i]);
		y = query(fty, yy_[i]);
		z = query(ftz, yy_[i]);
		ans += (long long) xx[i] * yy[i] * k - xx[i] * y - x * yy[i] + z;
		k = k_ - k, x = x_ - x, y = y_ - y, z = z_ - z;
		ans -= (long long) xx[i] * yy[i] * k - xx[i] * y - x * yy[i] + z;
		k_++, x_ += xx[i], y_ += yy[i], z_ += (long long) xx[i] * yy[i];
		update(ftk, yy_[i], n, 1);
		update(ftx, yy_[i], n, xx[i]);
		update(fty, yy_[i], n, yy[i]);
		update(ftz, yy_[i], n, (long long) xx[i] * yy[i]);
	}
	printf("%lld\n", ans);
	return 0;
}

Compilation message

social.c: In function 'main':
social.c:55:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   55 |  scanf("%d", &n);
      |  ^~~~~~~~~~~~~~~
social.c:57:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   57 |   scanf("%d%d", &xx[i], &yy[i]);
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2392 KB Output is correct
3 Correct 0 ms 2392 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 1 ms 2392 KB Output is correct
7 Correct 1 ms 2392 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 2 ms 2652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 3932 KB Output is correct
2 Correct 13 ms 4180 KB Output is correct
3 Correct 12 ms 3904 KB Output is correct
4 Correct 11 ms 3932 KB Output is correct
5 Correct 12 ms 4188 KB Output is correct
6 Correct 12 ms 3932 KB Output is correct
7 Correct 11 ms 3932 KB Output is correct
8 Correct 11 ms 3928 KB Output is correct
9 Correct 11 ms 3932 KB Output is correct
10 Correct 14 ms 4188 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 3932 KB Output is correct
2 Correct 13 ms 4188 KB Output is correct
3 Correct 12 ms 4184 KB Output is correct
4 Correct 13 ms 4188 KB Output is correct
5 Correct 14 ms 3928 KB Output is correct
6 Correct 14 ms 4184 KB Output is correct
7 Correct 13 ms 4184 KB Output is correct
8 Correct 14 ms 4188 KB Output is correct
9 Correct 11 ms 3928 KB Output is correct
10 Correct 16 ms 4188 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 3176 KB Output is correct
2 Correct 36 ms 5824 KB Output is correct
3 Correct 23 ms 5288 KB Output is correct
4 Correct 18 ms 4272 KB Output is correct
5 Correct 20 ms 4364 KB Output is correct
6 Correct 33 ms 5204 KB Output is correct
7 Correct 19 ms 4956 KB Output is correct
8 Correct 32 ms 5712 KB Output is correct
9 Correct 39 ms 5888 KB Output is correct
10 Correct 39 ms 5980 KB Output is correct