답안 #528287

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
528287 2022-02-19T19:41:05 Z rainboy Izbori (COCI22_izbori) C
40 / 110
3000 ms 3652 KB
#include <stdio.h>
#include <string.h>

#define N	200000

unsigned int X = 12345;

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

int aa[N], ii[N];

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) {
			int c = aa[ii[j]] != aa[i_] ? aa[ii[j]] - aa[i_] : ii[j] - i_;

			if (c == 0)
				j++;
			else if (c < 0) {
				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 kk[N * 2 + 1];
	static char marked[N];
	int n, h, i, j, d, k;
	long long ans;

	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%d", &aa[i]);
		ii[i] = i;
	}
	sort(ii, 0, n);
	ans = 0;
	for (i = 0; i < n; i = j) {
		j = i + 1;
		while (j < n && aa[ii[j]] == aa[ii[i]])
			j++;
		memset(marked, 0, n * sizeof *marked);
		for (h = i; h < j; h++)
			marked[ii[h]] = 1;
		memset(kk, 0, (n * 2 + 1) * sizeof *kk);
		d = n, kk[d] = 1, k = 0;
		for (i = 0; i < n; i++)
			if (marked[i]) {
				k += kk[d];
				ans += k;
				d++, kk[d]++;
			} else {
				d--;
				k -= kk[d];
				ans += k;
				kk[d]++;
			}
	}
	printf("%lld\n", ans);
	return 0;
}

Compilation message

Main.c: In function 'main':
Main.c:42:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   42 |  scanf("%d", &n);
      |  ^~~~~~~~~~~~~~~
Main.c:44:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   44 |   scanf("%d", &aa[i]);
      |   ^~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 284 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 276 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 284 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 276 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 2 ms 284 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 276 KB Output is correct
10 Correct 1 ms 284 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 284 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 30 ms 2444 KB Output is correct
2 Correct 36 ms 3080 KB Output is correct
3 Correct 22 ms 1856 KB Output is correct
4 Correct 40 ms 3344 KB Output is correct
5 Correct 40 ms 3408 KB Output is correct
6 Correct 40 ms 3508 KB Output is correct
7 Correct 40 ms 3524 KB Output is correct
8 Correct 41 ms 3524 KB Output is correct
9 Correct 41 ms 3552 KB Output is correct
10 Correct 42 ms 3500 KB Output is correct
11 Correct 32 ms 3540 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 284 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 276 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 2 ms 284 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 276 KB Output is correct
10 Correct 1 ms 284 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 284 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 30 ms 2444 KB Output is correct
19 Correct 36 ms 3080 KB Output is correct
20 Correct 22 ms 1856 KB Output is correct
21 Correct 40 ms 3344 KB Output is correct
22 Correct 40 ms 3408 KB Output is correct
23 Correct 40 ms 3508 KB Output is correct
24 Correct 40 ms 3524 KB Output is correct
25 Correct 41 ms 3524 KB Output is correct
26 Correct 41 ms 3552 KB Output is correct
27 Correct 42 ms 3500 KB Output is correct
28 Correct 32 ms 3540 KB Output is correct
29 Correct 46 ms 3652 KB Output is correct
30 Correct 1659 ms 1092 KB Output is correct
31 Execution timed out 3002 ms 1868 KB Time limit exceeded
32 Halted 0 ms 0 KB -