Submission #831769

# Submission time Handle Problem Language Result Execution time Memory
831769 2023-08-20T14:07:15 Z rainboy Mountains (NOI20_mountains) C
100 / 100
93 ms 10648 KB
#include <stdio.h>

#define N	300000

unsigned int X = 12345;

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

long long aa[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)
			if (aa[ii[j]] == aa[i_])
				j++;
			else if (aa[ii[j]] < aa[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 ii[N];
	int n, h, i, j, k;
	long long ans;

	scanf("%d", &n);
	for (i = 0; i < n; i++)
		scanf("%lld", &aa[i]);
	for (i = 0; i < n; 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++;
		for (h = i; h < j; h++) {
			k = query(ii[h]);
			ans += (long long) k * (i - k);
		}
		for (h = i; h < j; h++)
			update(ii[h], n);
	}
	printf("%lld\n", ans);
	return 0;
}

Compilation message

Mountains.c: In function 'main':
Mountains.c:56:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   56 |  scanf("%d", &n);
      |  ^~~~~~~~~~~~~~~
Mountains.c:58:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   58 |   scanf("%lld", &aa[i]);
      |   ^~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 292 KB Output is correct
2 Correct 60 ms 10544 KB Output is correct
3 Correct 60 ms 10444 KB Output is correct
4 Correct 60 ms 10476 KB Output is correct
5 Correct 60 ms 10472 KB Output is correct
6 Correct 60 ms 10488 KB Output is correct
7 Correct 61 ms 10380 KB Output is correct
8 Correct 61 ms 10372 KB Output is correct
9 Correct 64 ms 10416 KB Output is correct
10 Correct 63 ms 10528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 31 ms 5456 KB Output is correct
2 Correct 32 ms 5496 KB Output is correct
3 Correct 31 ms 5452 KB Output is correct
4 Correct 30 ms 5500 KB Output is correct
5 Correct 30 ms 5540 KB Output is correct
6 Correct 30 ms 5460 KB Output is correct
7 Correct 30 ms 5472 KB Output is correct
8 Correct 24 ms 5460 KB Output is correct
9 Correct 24 ms 5452 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 31 ms 5456 KB Output is correct
2 Correct 32 ms 5496 KB Output is correct
3 Correct 31 ms 5452 KB Output is correct
4 Correct 30 ms 5500 KB Output is correct
5 Correct 30 ms 5540 KB Output is correct
6 Correct 30 ms 5460 KB Output is correct
7 Correct 30 ms 5472 KB Output is correct
8 Correct 24 ms 5460 KB Output is correct
9 Correct 24 ms 5452 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 42 ms 5808 KB Output is correct
12 Correct 42 ms 5776 KB Output is correct
13 Correct 42 ms 5684 KB Output is correct
14 Correct 41 ms 5708 KB Output is correct
15 Correct 42 ms 5804 KB Output is correct
16 Correct 42 ms 5760 KB Output is correct
17 Correct 41 ms 5752 KB Output is correct
18 Correct 27 ms 5748 KB Output is correct
19 Correct 26 ms 5804 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 296 KB Output is correct
5 Correct 1 ms 296 KB Output is correct
6 Correct 1 ms 300 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 296 KB Output is correct
5 Correct 1 ms 296 KB Output is correct
6 Correct 1 ms 300 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 3 ms 596 KB Output is correct
12 Correct 3 ms 596 KB Output is correct
13 Correct 3 ms 528 KB Output is correct
14 Correct 3 ms 596 KB Output is correct
15 Correct 3 ms 600 KB Output is correct
16 Correct 3 ms 556 KB Output is correct
17 Correct 3 ms 536 KB Output is correct
18 Correct 3 ms 596 KB Output is correct
19 Correct 2 ms 468 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 31 ms 5456 KB Output is correct
2 Correct 32 ms 5496 KB Output is correct
3 Correct 31 ms 5452 KB Output is correct
4 Correct 30 ms 5500 KB Output is correct
5 Correct 30 ms 5540 KB Output is correct
6 Correct 30 ms 5460 KB Output is correct
7 Correct 30 ms 5472 KB Output is correct
8 Correct 24 ms 5460 KB Output is correct
9 Correct 24 ms 5452 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 42 ms 5808 KB Output is correct
12 Correct 42 ms 5776 KB Output is correct
13 Correct 42 ms 5684 KB Output is correct
14 Correct 41 ms 5708 KB Output is correct
15 Correct 42 ms 5804 KB Output is correct
16 Correct 42 ms 5760 KB Output is correct
17 Correct 41 ms 5752 KB Output is correct
18 Correct 27 ms 5748 KB Output is correct
19 Correct 26 ms 5804 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 71 ms 6664 KB Output is correct
22 Correct 68 ms 6608 KB Output is correct
23 Correct 72 ms 6660 KB Output is correct
24 Correct 67 ms 6680 KB Output is correct
25 Correct 67 ms 6604 KB Output is correct
26 Correct 68 ms 6664 KB Output is correct
27 Correct 74 ms 6668 KB Output is correct
28 Correct 48 ms 6604 KB Output is correct
29 Correct 43 ms 6640 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 292 KB Output is correct
2 Correct 60 ms 10544 KB Output is correct
3 Correct 60 ms 10444 KB Output is correct
4 Correct 60 ms 10476 KB Output is correct
5 Correct 60 ms 10472 KB Output is correct
6 Correct 60 ms 10488 KB Output is correct
7 Correct 61 ms 10380 KB Output is correct
8 Correct 61 ms 10372 KB Output is correct
9 Correct 64 ms 10416 KB Output is correct
10 Correct 63 ms 10528 KB Output is correct
11 Correct 31 ms 5456 KB Output is correct
12 Correct 32 ms 5496 KB Output is correct
13 Correct 31 ms 5452 KB Output is correct
14 Correct 30 ms 5500 KB Output is correct
15 Correct 30 ms 5540 KB Output is correct
16 Correct 30 ms 5460 KB Output is correct
17 Correct 30 ms 5472 KB Output is correct
18 Correct 24 ms 5460 KB Output is correct
19 Correct 24 ms 5452 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 42 ms 5808 KB Output is correct
22 Correct 42 ms 5776 KB Output is correct
23 Correct 42 ms 5684 KB Output is correct
24 Correct 41 ms 5708 KB Output is correct
25 Correct 42 ms 5804 KB Output is correct
26 Correct 42 ms 5760 KB Output is correct
27 Correct 41 ms 5752 KB Output is correct
28 Correct 27 ms 5748 KB Output is correct
29 Correct 26 ms 5804 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 1 ms 296 KB Output is correct
35 Correct 1 ms 296 KB Output is correct
36 Correct 1 ms 300 KB Output is correct
37 Correct 1 ms 212 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 0 ms 212 KB Output is correct
40 Correct 1 ms 212 KB Output is correct
41 Correct 3 ms 596 KB Output is correct
42 Correct 3 ms 596 KB Output is correct
43 Correct 3 ms 528 KB Output is correct
44 Correct 3 ms 596 KB Output is correct
45 Correct 3 ms 600 KB Output is correct
46 Correct 3 ms 556 KB Output is correct
47 Correct 3 ms 536 KB Output is correct
48 Correct 3 ms 596 KB Output is correct
49 Correct 2 ms 468 KB Output is correct
50 Correct 0 ms 212 KB Output is correct
51 Correct 71 ms 6664 KB Output is correct
52 Correct 68 ms 6608 KB Output is correct
53 Correct 72 ms 6660 KB Output is correct
54 Correct 67 ms 6680 KB Output is correct
55 Correct 67 ms 6604 KB Output is correct
56 Correct 68 ms 6664 KB Output is correct
57 Correct 74 ms 6668 KB Output is correct
58 Correct 48 ms 6604 KB Output is correct
59 Correct 43 ms 6640 KB Output is correct
60 Correct 0 ms 212 KB Output is correct
61 Correct 87 ms 10440 KB Output is correct
62 Correct 89 ms 10432 KB Output is correct
63 Correct 91 ms 10476 KB Output is correct
64 Correct 93 ms 10648 KB Output is correct
65 Correct 89 ms 10404 KB Output is correct
66 Correct 89 ms 10436 KB Output is correct
67 Correct 88 ms 10444 KB Output is correct
68 Correct 87 ms 10444 KB Output is correct
69 Correct 75 ms 6776 KB Output is correct
70 Correct 1 ms 212 KB Output is correct