Submission #993597

# Submission time Handle Problem Language Result Execution time Memory
993597 2024-06-06T06:21:13 Z Trisanu_Das Real Mountains (CCO23_day1problem2) C++17
25 / 25
398 ms 29632 KB
#include <bits/stdc++.h>
#define N	1000000
#define MD	1000003
using namespace std;
 
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, al, ar, ak, as, l, r, k, ans;
	cin >> n;
	for (i = 1; i <= n; i++) {
		cin >> 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 (h = n - 1, l = n + 2, r = -1; h > 0; h--) {
		i = ii[h];
		l = min(l, i), r = max(r, i);
		p = pp[i], q = qq[i];
		qq[p] = q, pp[q] = p, bb[p] = aa[i];
		k = r - l + 1 - (n - h);
		if (k == 0) continue;
		al = aa[ii[h - 1]], ar = aa[ii[h]];
		ak = ar - al, as = (long long) ak * (al + ar - 1) / 2 % MD;
		ans = (ans + ((long long) as * 3 + ak * 2) * k) % MD;
		if (k == 1) ans = (ans + ((long long) bb[l - 1] + bb[pp[r + 1]]) * ak - (long long) (as + ak) * 2) % MD;
		else ans = (ans + ((long long) bb[l - 1] + bb[pp[r + 1]] + aa[ii[h]]) * ak - (long long) (as + ak) * 3) % MD;
	}
	if (ans < 0) ans += MD;
	cout << ans << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 444 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 456 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 444 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 456 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 472 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 484 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 452 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 444 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 456 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 472 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 484 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 452 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 3 ms 604 KB Output is correct
36 Correct 2 ms 604 KB Output is correct
37 Correct 2 ms 608 KB Output is correct
38 Correct 2 ms 604 KB Output is correct
39 Correct 2 ms 500 KB Output is correct
40 Correct 1 ms 348 KB Output is correct
41 Correct 1 ms 348 KB Output is correct
42 Correct 2 ms 348 KB Output is correct
43 Correct 2 ms 604 KB Output is correct
44 Correct 2 ms 352 KB Output is correct
45 Correct 1 ms 604 KB Output is correct
46 Correct 3 ms 604 KB Output is correct
47 Correct 2 ms 604 KB Output is correct
48 Correct 2 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 444 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 456 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 472 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 484 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 452 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 3 ms 604 KB Output is correct
36 Correct 2 ms 604 KB Output is correct
37 Correct 2 ms 608 KB Output is correct
38 Correct 2 ms 604 KB Output is correct
39 Correct 2 ms 500 KB Output is correct
40 Correct 1 ms 348 KB Output is correct
41 Correct 1 ms 348 KB Output is correct
42 Correct 2 ms 348 KB Output is correct
43 Correct 2 ms 604 KB Output is correct
44 Correct 2 ms 352 KB Output is correct
45 Correct 1 ms 604 KB Output is correct
46 Correct 3 ms 604 KB Output is correct
47 Correct 2 ms 604 KB Output is correct
48 Correct 2 ms 604 KB Output is correct
49 Correct 3 ms 604 KB Output is correct
50 Correct 3 ms 604 KB Output is correct
51 Correct 3 ms 604 KB Output is correct
52 Correct 3 ms 460 KB Output is correct
53 Correct 2 ms 536 KB Output is correct
54 Correct 1 ms 348 KB Output is correct
55 Correct 1 ms 448 KB Output is correct
56 Correct 2 ms 348 KB Output is correct
57 Correct 2 ms 604 KB Output is correct
58 Correct 3 ms 604 KB Output is correct
59 Correct 2 ms 604 KB Output is correct
60 Correct 2 ms 604 KB Output is correct
61 Correct 3 ms 604 KB Output is correct
62 Correct 2 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 444 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 456 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 472 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 484 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 452 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 196 ms 22624 KB Output is correct
36 Correct 160 ms 22612 KB Output is correct
37 Correct 188 ms 22616 KB Output is correct
38 Correct 170 ms 22616 KB Output is correct
39 Correct 168 ms 22816 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 124 ms 21864 KB Output is correct
43 Correct 118 ms 21844 KB Output is correct
44 Correct 124 ms 22036 KB Output is correct
45 Correct 123 ms 21068 KB Output is correct
46 Correct 127 ms 21072 KB Output is correct
47 Correct 122 ms 21076 KB Output is correct
48 Correct 147 ms 22752 KB Output is correct
49 Correct 136 ms 22592 KB Output is correct
50 Correct 144 ms 22612 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 444 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 456 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 472 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 484 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 452 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 3 ms 604 KB Output is correct
36 Correct 2 ms 604 KB Output is correct
37 Correct 2 ms 608 KB Output is correct
38 Correct 2 ms 604 KB Output is correct
39 Correct 2 ms 500 KB Output is correct
40 Correct 1 ms 348 KB Output is correct
41 Correct 1 ms 348 KB Output is correct
42 Correct 2 ms 348 KB Output is correct
43 Correct 2 ms 604 KB Output is correct
44 Correct 2 ms 352 KB Output is correct
45 Correct 1 ms 604 KB Output is correct
46 Correct 3 ms 604 KB Output is correct
47 Correct 2 ms 604 KB Output is correct
48 Correct 2 ms 604 KB Output is correct
49 Correct 196 ms 22624 KB Output is correct
50 Correct 160 ms 22612 KB Output is correct
51 Correct 188 ms 22616 KB Output is correct
52 Correct 170 ms 22616 KB Output is correct
53 Correct 168 ms 22816 KB Output is correct
54 Correct 0 ms 348 KB Output is correct
55 Correct 0 ms 348 KB Output is correct
56 Correct 124 ms 21864 KB Output is correct
57 Correct 118 ms 21844 KB Output is correct
58 Correct 124 ms 22036 KB Output is correct
59 Correct 123 ms 21068 KB Output is correct
60 Correct 127 ms 21072 KB Output is correct
61 Correct 122 ms 21076 KB Output is correct
62 Correct 147 ms 22752 KB Output is correct
63 Correct 136 ms 22592 KB Output is correct
64 Correct 144 ms 22612 KB Output is correct
65 Correct 336 ms 26544 KB Output is correct
66 Correct 358 ms 26508 KB Output is correct
67 Correct 332 ms 26712 KB Output is correct
68 Correct 349 ms 26964 KB Output is correct
69 Correct 326 ms 26700 KB Output is correct
70 Correct 119 ms 21940 KB Output is correct
71 Correct 127 ms 22224 KB Output is correct
72 Correct 121 ms 21844 KB Output is correct
73 Correct 238 ms 26544 KB Output is correct
74 Correct 246 ms 26680 KB Output is correct
75 Correct 238 ms 26708 KB Output is correct
76 Correct 275 ms 26708 KB Output is correct
77 Correct 281 ms 26620 KB Output is correct
78 Correct 277 ms 26504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 444 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 456 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 472 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 484 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 452 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 3 ms 604 KB Output is correct
36 Correct 2 ms 604 KB Output is correct
37 Correct 2 ms 608 KB Output is correct
38 Correct 2 ms 604 KB Output is correct
39 Correct 2 ms 500 KB Output is correct
40 Correct 1 ms 348 KB Output is correct
41 Correct 1 ms 348 KB Output is correct
42 Correct 2 ms 348 KB Output is correct
43 Correct 2 ms 604 KB Output is correct
44 Correct 2 ms 352 KB Output is correct
45 Correct 1 ms 604 KB Output is correct
46 Correct 3 ms 604 KB Output is correct
47 Correct 2 ms 604 KB Output is correct
48 Correct 2 ms 604 KB Output is correct
49 Correct 3 ms 604 KB Output is correct
50 Correct 3 ms 604 KB Output is correct
51 Correct 3 ms 604 KB Output is correct
52 Correct 3 ms 460 KB Output is correct
53 Correct 2 ms 536 KB Output is correct
54 Correct 1 ms 348 KB Output is correct
55 Correct 1 ms 448 KB Output is correct
56 Correct 2 ms 348 KB Output is correct
57 Correct 2 ms 604 KB Output is correct
58 Correct 3 ms 604 KB Output is correct
59 Correct 2 ms 604 KB Output is correct
60 Correct 2 ms 604 KB Output is correct
61 Correct 3 ms 604 KB Output is correct
62 Correct 2 ms 604 KB Output is correct
63 Correct 196 ms 22624 KB Output is correct
64 Correct 160 ms 22612 KB Output is correct
65 Correct 188 ms 22616 KB Output is correct
66 Correct 170 ms 22616 KB Output is correct
67 Correct 168 ms 22816 KB Output is correct
68 Correct 0 ms 348 KB Output is correct
69 Correct 0 ms 348 KB Output is correct
70 Correct 124 ms 21864 KB Output is correct
71 Correct 118 ms 21844 KB Output is correct
72 Correct 124 ms 22036 KB Output is correct
73 Correct 123 ms 21068 KB Output is correct
74 Correct 127 ms 21072 KB Output is correct
75 Correct 122 ms 21076 KB Output is correct
76 Correct 147 ms 22752 KB Output is correct
77 Correct 136 ms 22592 KB Output is correct
78 Correct 144 ms 22612 KB Output is correct
79 Correct 336 ms 26544 KB Output is correct
80 Correct 358 ms 26508 KB Output is correct
81 Correct 332 ms 26712 KB Output is correct
82 Correct 349 ms 26964 KB Output is correct
83 Correct 326 ms 26700 KB Output is correct
84 Correct 119 ms 21940 KB Output is correct
85 Correct 127 ms 22224 KB Output is correct
86 Correct 121 ms 21844 KB Output is correct
87 Correct 238 ms 26544 KB Output is correct
88 Correct 246 ms 26680 KB Output is correct
89 Correct 238 ms 26708 KB Output is correct
90 Correct 275 ms 26708 KB Output is correct
91 Correct 281 ms 26620 KB Output is correct
92 Correct 277 ms 26504 KB Output is correct
93 Correct 123 ms 21916 KB Output is correct
94 Correct 303 ms 27732 KB Output is correct
95 Correct 300 ms 27732 KB Output is correct
96 Correct 307 ms 27820 KB Output is correct
97 Correct 343 ms 29504 KB Output is correct
98 Correct 343 ms 29524 KB Output is correct
99 Correct 339 ms 29524 KB Output is correct
100 Correct 395 ms 29524 KB Output is correct
101 Correct 392 ms 29632 KB Output is correct
102 Correct 392 ms 29524 KB Output is correct
103 Correct 398 ms 29592 KB Output is correct
104 Correct 396 ms 29524 KB Output is correct
105 Correct 117 ms 21980 KB Output is correct
106 Correct 115 ms 22028 KB Output is correct