답안 #823229

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
823229 2023-08-12T09:44:43 Z rainboy Real Mountains (CCO23_day1problem2) C
18 / 25
303 ms 26376 KB
#include <stdio.h>

#define N	1000000
#define INF	0x3f3f3f3f
#define MD	1000003
#define A	1000000

int min(int a, int b) { return a < b ? a : b; }
int max(int a, int b) { return a > b ? a : b; }

unsigned int X = 12345;

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

int aa[N + 2];

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 main() {
	static int ii[N], pp[N + 2], qq[N + 2], bb[N + 2];
	int n, h, i, p, q, a, l, r, k, ans;

	scanf("%d", &n);
	for (i = 1; i <= n; i++) {
		scanf("%d", &aa[i]);
		ii[i - 1] = i;
	}
	sort(ii, 0, n);
	for (i = 0; i <= n + 1; i++)
		pp[i] = i - 1, qq[i] = i + 1;
	ans = 0;
	for (a = A, h = n - 1, l = n + 2, r = -1; a > 0; a--) {
		while (h >= 0 && aa[i = ii[h]] > a) {
			l = min(l, i), r = max(r, i);
			p = pp[i], q = qq[i];
			qq[p] = q, pp[q] = p, bb[p] = aa[i];
			h--;
		}
		if (h == n - 1)
			continue;
		k = r - l + 1 - (n - 1 - h);
		if (k == 0)
			continue;
		ans = (ans + (long long) (a * 3 + 2) * k) % MD;
		if (k == 1)
			ans = (ans + bb[l - 1] + bb[pp[r + 1]] - (a + 1) * 2) % MD;
		else
			ans = (ans + bb[l - 1] + bb[pp[r + 1]] + aa[ii[h + 1]] - (a + 1) * 3) % MD;
	}
	printf("%d\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 2 ms 212 KB Output is correct
2 Correct 2 ms 212 KB Output is correct
3 Correct 2 ms 212 KB Output is correct
4 Correct 2 ms 468 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 3 ms 340 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 2 ms 340 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 2 ms 340 KB Output is correct
12 Correct 2 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 212 KB Output is correct
2 Correct 2 ms 212 KB Output is correct
3 Correct 2 ms 212 KB Output is correct
4 Correct 2 ms 468 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 3 ms 340 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 2 ms 340 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 2 ms 340 KB Output is correct
12 Correct 2 ms 340 KB Output is correct
13 Correct 2 ms 340 KB Output is correct
14 Correct 2 ms 212 KB Output is correct
15 Correct 2 ms 212 KB Output is correct
16 Correct 2 ms 340 KB Output is correct
17 Correct 2 ms 340 KB Output is correct
18 Correct 2 ms 340 KB Output is correct
19 Correct 2 ms 340 KB Output is correct
20 Correct 2 ms 340 KB Output is correct
21 Correct 2 ms 340 KB Output is correct
22 Correct 2 ms 340 KB Output is correct
23 Correct 2 ms 340 KB Output is correct
24 Correct 2 ms 340 KB Output is correct
25 Correct 2 ms 340 KB Output is correct
26 Correct 3 ms 340 KB Output is correct
27 Correct 2 ms 340 KB Output is correct
28 Correct 3 ms 468 KB Output is correct
29 Correct 2 ms 212 KB Output is correct
30 Correct 2 ms 212 KB Output is correct
31 Correct 2 ms 212 KB Output is correct
32 Correct 3 ms 212 KB Output is correct
33 Correct 2 ms 212 KB Output is correct
34 Correct 2 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 212 KB Output is correct
2 Correct 2 ms 212 KB Output is correct
3 Correct 2 ms 212 KB Output is correct
4 Correct 2 ms 468 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 3 ms 340 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 2 ms 340 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 2 ms 340 KB Output is correct
12 Correct 2 ms 340 KB Output is correct
13 Correct 2 ms 340 KB Output is correct
14 Correct 2 ms 212 KB Output is correct
15 Correct 2 ms 212 KB Output is correct
16 Correct 2 ms 340 KB Output is correct
17 Correct 2 ms 340 KB Output is correct
18 Correct 2 ms 340 KB Output is correct
19 Correct 2 ms 340 KB Output is correct
20 Correct 2 ms 340 KB Output is correct
21 Correct 2 ms 340 KB Output is correct
22 Correct 2 ms 340 KB Output is correct
23 Correct 2 ms 340 KB Output is correct
24 Correct 2 ms 340 KB Output is correct
25 Correct 2 ms 340 KB Output is correct
26 Correct 3 ms 340 KB Output is correct
27 Correct 2 ms 340 KB Output is correct
28 Correct 3 ms 468 KB Output is correct
29 Correct 2 ms 212 KB Output is correct
30 Correct 2 ms 212 KB Output is correct
31 Correct 2 ms 212 KB Output is correct
32 Correct 3 ms 212 KB Output is correct
33 Correct 2 ms 212 KB Output is correct
34 Correct 2 ms 212 KB Output is correct
35 Correct 10 ms 420 KB Output is correct
36 Correct 10 ms 444 KB Output is correct
37 Correct 10 ms 428 KB Output is correct
38 Correct 10 ms 340 KB Output is correct
39 Correct 11 ms 436 KB Output is correct
40 Correct 10 ms 340 KB Output is correct
41 Correct 10 ms 340 KB Output is correct
42 Correct 10 ms 340 KB Output is correct
43 Correct 10 ms 340 KB Output is correct
44 Correct 10 ms 440 KB Output is correct
45 Correct 11 ms 444 KB Output is correct
46 Correct 10 ms 340 KB Output is correct
47 Correct 11 ms 340 KB Output is correct
48 Correct 11 ms 456 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 212 KB Output is correct
2 Correct 2 ms 212 KB Output is correct
3 Correct 2 ms 212 KB Output is correct
4 Correct 2 ms 468 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 3 ms 340 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 2 ms 340 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 2 ms 340 KB Output is correct
12 Correct 2 ms 340 KB Output is correct
13 Correct 2 ms 340 KB Output is correct
14 Correct 2 ms 212 KB Output is correct
15 Correct 2 ms 212 KB Output is correct
16 Correct 2 ms 340 KB Output is correct
17 Correct 2 ms 340 KB Output is correct
18 Correct 2 ms 340 KB Output is correct
19 Correct 2 ms 340 KB Output is correct
20 Correct 2 ms 340 KB Output is correct
21 Correct 2 ms 340 KB Output is correct
22 Correct 2 ms 340 KB Output is correct
23 Correct 2 ms 340 KB Output is correct
24 Correct 2 ms 340 KB Output is correct
25 Correct 2 ms 340 KB Output is correct
26 Correct 3 ms 340 KB Output is correct
27 Correct 2 ms 340 KB Output is correct
28 Correct 3 ms 468 KB Output is correct
29 Correct 2 ms 212 KB Output is correct
30 Correct 2 ms 212 KB Output is correct
31 Correct 2 ms 212 KB Output is correct
32 Correct 3 ms 212 KB Output is correct
33 Correct 2 ms 212 KB Output is correct
34 Correct 2 ms 212 KB Output is correct
35 Correct 10 ms 420 KB Output is correct
36 Correct 10 ms 444 KB Output is correct
37 Correct 10 ms 428 KB Output is correct
38 Correct 10 ms 340 KB Output is correct
39 Correct 11 ms 436 KB Output is correct
40 Correct 10 ms 340 KB Output is correct
41 Correct 10 ms 340 KB Output is correct
42 Correct 10 ms 340 KB Output is correct
43 Correct 10 ms 340 KB Output is correct
44 Correct 10 ms 440 KB Output is correct
45 Correct 11 ms 444 KB Output is correct
46 Correct 10 ms 340 KB Output is correct
47 Correct 11 ms 340 KB Output is correct
48 Correct 11 ms 456 KB Output is correct
49 Incorrect 9 ms 468 KB Output isn't correct
50 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 212 KB Output is correct
2 Correct 2 ms 212 KB Output is correct
3 Correct 2 ms 212 KB Output is correct
4 Correct 2 ms 468 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 3 ms 340 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 2 ms 340 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 2 ms 340 KB Output is correct
12 Correct 2 ms 340 KB Output is correct
13 Correct 2 ms 340 KB Output is correct
14 Correct 2 ms 212 KB Output is correct
15 Correct 2 ms 212 KB Output is correct
16 Correct 2 ms 340 KB Output is correct
17 Correct 2 ms 340 KB Output is correct
18 Correct 2 ms 340 KB Output is correct
19 Correct 2 ms 340 KB Output is correct
20 Correct 2 ms 340 KB Output is correct
21 Correct 2 ms 340 KB Output is correct
22 Correct 2 ms 340 KB Output is correct
23 Correct 2 ms 340 KB Output is correct
24 Correct 2 ms 340 KB Output is correct
25 Correct 2 ms 340 KB Output is correct
26 Correct 3 ms 340 KB Output is correct
27 Correct 2 ms 340 KB Output is correct
28 Correct 3 ms 468 KB Output is correct
29 Correct 2 ms 212 KB Output is correct
30 Correct 2 ms 212 KB Output is correct
31 Correct 2 ms 212 KB Output is correct
32 Correct 3 ms 212 KB Output is correct
33 Correct 2 ms 212 KB Output is correct
34 Correct 2 ms 212 KB Output is correct
35 Correct 119 ms 19720 KB Output is correct
36 Correct 118 ms 19736 KB Output is correct
37 Correct 121 ms 19836 KB Output is correct
38 Correct 137 ms 19844 KB Output is correct
39 Correct 116 ms 19784 KB Output is correct
40 Correct 2 ms 312 KB Output is correct
41 Correct 2 ms 212 KB Output is correct
42 Correct 88 ms 19736 KB Output is correct
43 Correct 102 ms 19748 KB Output is correct
44 Correct 94 ms 19732 KB Output is correct
45 Correct 79 ms 18132 KB Output is correct
46 Correct 79 ms 18076 KB Output is correct
47 Correct 81 ms 17976 KB Output is correct
48 Correct 95 ms 19744 KB Output is correct
49 Correct 95 ms 19816 KB Output is correct
50 Correct 96 ms 19788 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 212 KB Output is correct
2 Correct 2 ms 212 KB Output is correct
3 Correct 2 ms 212 KB Output is correct
4 Correct 2 ms 468 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 3 ms 340 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 2 ms 340 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 2 ms 340 KB Output is correct
12 Correct 2 ms 340 KB Output is correct
13 Correct 2 ms 340 KB Output is correct
14 Correct 2 ms 212 KB Output is correct
15 Correct 2 ms 212 KB Output is correct
16 Correct 2 ms 340 KB Output is correct
17 Correct 2 ms 340 KB Output is correct
18 Correct 2 ms 340 KB Output is correct
19 Correct 2 ms 340 KB Output is correct
20 Correct 2 ms 340 KB Output is correct
21 Correct 2 ms 340 KB Output is correct
22 Correct 2 ms 340 KB Output is correct
23 Correct 2 ms 340 KB Output is correct
24 Correct 2 ms 340 KB Output is correct
25 Correct 2 ms 340 KB Output is correct
26 Correct 3 ms 340 KB Output is correct
27 Correct 2 ms 340 KB Output is correct
28 Correct 3 ms 468 KB Output is correct
29 Correct 2 ms 212 KB Output is correct
30 Correct 2 ms 212 KB Output is correct
31 Correct 2 ms 212 KB Output is correct
32 Correct 3 ms 212 KB Output is correct
33 Correct 2 ms 212 KB Output is correct
34 Correct 2 ms 212 KB Output is correct
35 Correct 10 ms 420 KB Output is correct
36 Correct 10 ms 444 KB Output is correct
37 Correct 10 ms 428 KB Output is correct
38 Correct 10 ms 340 KB Output is correct
39 Correct 11 ms 436 KB Output is correct
40 Correct 10 ms 340 KB Output is correct
41 Correct 10 ms 340 KB Output is correct
42 Correct 10 ms 340 KB Output is correct
43 Correct 10 ms 340 KB Output is correct
44 Correct 10 ms 440 KB Output is correct
45 Correct 11 ms 444 KB Output is correct
46 Correct 10 ms 340 KB Output is correct
47 Correct 11 ms 340 KB Output is correct
48 Correct 11 ms 456 KB Output is correct
49 Correct 119 ms 19720 KB Output is correct
50 Correct 118 ms 19736 KB Output is correct
51 Correct 121 ms 19836 KB Output is correct
52 Correct 137 ms 19844 KB Output is correct
53 Correct 116 ms 19784 KB Output is correct
54 Correct 2 ms 312 KB Output is correct
55 Correct 2 ms 212 KB Output is correct
56 Correct 88 ms 19736 KB Output is correct
57 Correct 102 ms 19748 KB Output is correct
58 Correct 94 ms 19732 KB Output is correct
59 Correct 79 ms 18132 KB Output is correct
60 Correct 79 ms 18076 KB Output is correct
61 Correct 81 ms 17976 KB Output is correct
62 Correct 95 ms 19744 KB Output is correct
63 Correct 95 ms 19816 KB Output is correct
64 Correct 96 ms 19788 KB Output is correct
65 Correct 277 ms 25972 KB Output is correct
66 Correct 303 ms 24108 KB Output is correct
67 Correct 277 ms 25436 KB Output is correct
68 Correct 291 ms 26228 KB Output is correct
69 Correct 277 ms 25932 KB Output is correct
70 Correct 103 ms 21772 KB Output is correct
71 Correct 106 ms 21468 KB Output is correct
72 Correct 129 ms 21788 KB Output is correct
73 Correct 163 ms 26376 KB Output is correct
74 Correct 161 ms 25288 KB Output is correct
75 Correct 164 ms 25948 KB Output is correct
76 Correct 213 ms 26052 KB Output is correct
77 Correct 236 ms 25752 KB Output is correct
78 Correct 217 ms 26240 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 212 KB Output is correct
2 Correct 2 ms 212 KB Output is correct
3 Correct 2 ms 212 KB Output is correct
4 Correct 2 ms 468 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 3 ms 340 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 2 ms 340 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 2 ms 340 KB Output is correct
12 Correct 2 ms 340 KB Output is correct
13 Correct 2 ms 340 KB Output is correct
14 Correct 2 ms 212 KB Output is correct
15 Correct 2 ms 212 KB Output is correct
16 Correct 2 ms 340 KB Output is correct
17 Correct 2 ms 340 KB Output is correct
18 Correct 2 ms 340 KB Output is correct
19 Correct 2 ms 340 KB Output is correct
20 Correct 2 ms 340 KB Output is correct
21 Correct 2 ms 340 KB Output is correct
22 Correct 2 ms 340 KB Output is correct
23 Correct 2 ms 340 KB Output is correct
24 Correct 2 ms 340 KB Output is correct
25 Correct 2 ms 340 KB Output is correct
26 Correct 3 ms 340 KB Output is correct
27 Correct 2 ms 340 KB Output is correct
28 Correct 3 ms 468 KB Output is correct
29 Correct 2 ms 212 KB Output is correct
30 Correct 2 ms 212 KB Output is correct
31 Correct 2 ms 212 KB Output is correct
32 Correct 3 ms 212 KB Output is correct
33 Correct 2 ms 212 KB Output is correct
34 Correct 2 ms 212 KB Output is correct
35 Correct 10 ms 420 KB Output is correct
36 Correct 10 ms 444 KB Output is correct
37 Correct 10 ms 428 KB Output is correct
38 Correct 10 ms 340 KB Output is correct
39 Correct 11 ms 436 KB Output is correct
40 Correct 10 ms 340 KB Output is correct
41 Correct 10 ms 340 KB Output is correct
42 Correct 10 ms 340 KB Output is correct
43 Correct 10 ms 340 KB Output is correct
44 Correct 10 ms 440 KB Output is correct
45 Correct 11 ms 444 KB Output is correct
46 Correct 10 ms 340 KB Output is correct
47 Correct 11 ms 340 KB Output is correct
48 Correct 11 ms 456 KB Output is correct
49 Incorrect 9 ms 468 KB Output isn't correct
50 Halted 0 ms 0 KB -