답안 #528292

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
528292 2022-02-19T19:59:06 Z rainboy Izbori (COCI22_izbori) C
25 / 110
3000 ms 2356 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 xx[N * 2 + 4];

void update(int l, int r, int x) {
	int i;

	for (i = l; i <= r; i++)
		xx[i] += x;
}

long long query(int r) {
	int i;
	long long ans;

	ans = 0;
	for (i = 0; i <= r; i++)
		ans += (long long) xx[i] * (r - i + 1);
	return ans;
}

int main() {
	int n, h, i, i_, j, j_, k, d;
	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(xx, 0, (n * 2 + 4) * sizeof *xx);
		d = n + 2;
		update(d, d, 1);
		for (i_ = -1, h = i; h <= j; h++) {
			j_ = h == j ? n : ii[h], k = j_ - i_ - 1;
			if (k > 0) {
				ans += query(d - 2) - query(d - k - 2);
				update(d - k, d - 1, 1);
				d -= k;
			}
			if (h < j) {
				d++;
				ans += query(d - 1) - query(d - 2);
				update(d, d, 1);
				i_ = ii[h];
			}
		}
	}
	printf("%lld\n", ans);
	return 0;
}

Compilation message

Main.c: In function 'main':
Main.c:59:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   59 |  scanf("%d", &n);
      |  ^~~~~~~~~~~~~~~
Main.c:61:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   61 |   scanf("%d", &aa[i]);
      |   ^~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 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 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 3 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 7 ms 332 KB Output is correct
10 Correct 7 ms 204 KB Output is correct
11 Correct 7 ms 328 KB Output is correct
12 Correct 7 ms 332 KB Output is correct
13 Correct 7 ms 332 KB Output is correct
14 Correct 7 ms 296 KB Output is correct
15 Correct 7 ms 204 KB Output is correct
16 Correct 7 ms 324 KB Output is correct
17 Correct 10 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3070 ms 2356 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 3 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 7 ms 332 KB Output is correct
10 Correct 7 ms 204 KB Output is correct
11 Correct 7 ms 328 KB Output is correct
12 Correct 7 ms 332 KB Output is correct
13 Correct 7 ms 332 KB Output is correct
14 Correct 7 ms 296 KB Output is correct
15 Correct 7 ms 204 KB Output is correct
16 Correct 7 ms 324 KB Output is correct
17 Correct 10 ms 332 KB Output is correct
18 Execution timed out 3070 ms 2356 KB Time limit exceeded
19 Halted 0 ms 0 KB -