답안 #944494

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
944494 2024-03-12T19:16:24 Z rainboy 공장 (KOI13_factory) C
20 / 20
243 ms 18772 KB
#include <stdio.h>

#define N	500000

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

int ft[N];

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

int query(int i) {
	int x = 0;

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

int main() {
	static int aa[N], bb[N], ii[N], jj[N], jj_[N];
	int n, h, i, j;
	long long ans;

	scanf("%d", &n);
	for (i = 0; i < n; i++)
		scanf("%d", &aa[i]);
	for (j = 0; j < n; j++)
		scanf("%d", &bb[j]);
	for (i = 0; i < n; i++)
		ii[i] = i;
	ww = aa, sort(ii, 0, n);
	for (j = 0; j < n; j++)
		jj[j] = j;
	ww = bb, sort(jj, 0, n);
	for (h = 0; h < n; h++)
		jj_[ii[h]] = jj[h];
	ans = 0;
	for (i = n - 1; i >= 0; i--) {
		ans += query(jj_[i]);
		update(jj_[i], n);
	}
	printf("%lld\n", ans);
	return 0;
}

Compilation message

factory.c: In function 'main':
factory.c:56:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   56 |  scanf("%d", &n);
      |  ^~~~~~~~~~~~~~~
factory.c:58:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   58 |   scanf("%d", &aa[i]);
      |   ^~~~~~~~~~~~~~~~~~~
factory.c:60:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   60 |   scanf("%d", &bb[j]);
      |   ^~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 10588 KB Output is correct
2 Correct 1 ms 10588 KB Output is correct
3 Correct 2 ms 10588 KB Output is correct
4 Correct 1 ms 10668 KB Output is correct
5 Correct 1 ms 10588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 10588 KB Output is correct
2 Correct 3 ms 10588 KB Output is correct
3 Correct 6 ms 10844 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 11096 KB Output is correct
2 Correct 22 ms 11356 KB Output is correct
3 Correct 30 ms 11880 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 43 ms 12624 KB Output is correct
2 Correct 70 ms 13644 KB Output is correct
3 Correct 88 ms 14124 KB Output is correct
4 Correct 137 ms 15760 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 187 ms 16980 KB Output is correct
2 Correct 223 ms 18760 KB Output is correct
3 Correct 224 ms 18772 KB Output is correct
4 Correct 234 ms 18768 KB Output is correct
5 Correct 243 ms 18772 KB Output is correct
6 Correct 234 ms 18768 KB Output is correct