Submission #659704

# Submission time Handle Problem Language Result Execution time Memory
659704 2022-11-19T05:45:20 Z Sohsoh84 Diversity (CEOI21_diversity) C++17
64 / 100
862 ms 3776 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;

#define all(x)			(x).begin(),(x).end()
#define X			first
#define Y			second
#define sep			' '
#define endl			'\n'
#define debug(x)		cerr << #x << ": " <<  x << endl;

const ll MAXN = 1e6 + 10;
const ll INF = 4e18;

int n, q, cnt[MAXN], A[MAXN];

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n >> q;
	for (int i = 1; i <= n; i++) {
		int A[i];
		cin >> A[i];
		cnt[A[i]]++;
	}

	vector<int> vec = {0};
	for (int i = 0; i < MAXN; i++)
		if (cnt[i])
			vec.push_back(cnt[i]);

	int m = vec.size() - 1;
	sort(all(vec));

	ll s = 0, ans = 0, j = 0;
	for (int i = 1; i <= m; i++) {	
		if (i & 1) {
			j += vec[i];
			ans += j * (n - j); // n * j - j * j
		} else ans += (s - j) * (n - s + j);

		s += vec[i];
	}

	cout << ans + 1ll * n * (n + 1) / 2 << endl;
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 2 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 82 ms 660 KB Output is correct
5 Correct 355 ms 1076 KB Output is correct
6 Correct 802 ms 1588 KB Output is correct
7 Correct 829 ms 1516 KB Output is correct
8 Correct 823 ms 1532 KB Output is correct
9 Correct 820 ms 1552 KB Output is correct
10 Correct 804 ms 1452 KB Output is correct
11 Correct 817 ms 1512 KB Output is correct
12 Correct 822 ms 1448 KB Output is correct
13 Correct 812 ms 1636 KB Output is correct
14 Correct 816 ms 1428 KB Output is correct
15 Correct 804 ms 1496 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 82 ms 660 KB Output is correct
5 Correct 355 ms 1076 KB Output is correct
6 Correct 802 ms 1588 KB Output is correct
7 Correct 829 ms 1516 KB Output is correct
8 Correct 823 ms 1532 KB Output is correct
9 Correct 820 ms 1552 KB Output is correct
10 Correct 804 ms 1452 KB Output is correct
11 Correct 817 ms 1512 KB Output is correct
12 Correct 822 ms 1448 KB Output is correct
13 Correct 812 ms 1636 KB Output is correct
14 Correct 816 ms 1428 KB Output is correct
15 Correct 804 ms 1496 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 2 ms 340 KB Output is correct
19 Correct 76 ms 592 KB Output is correct
20 Correct 356 ms 1036 KB Output is correct
21 Correct 815 ms 1464 KB Output is correct
22 Correct 823 ms 1480 KB Output is correct
23 Correct 828 ms 1648 KB Output is correct
24 Correct 804 ms 1380 KB Output is correct
25 Correct 809 ms 1592 KB Output is correct
26 Correct 816 ms 1484 KB Output is correct
27 Correct 814 ms 1504 KB Output is correct
28 Correct 836 ms 1400 KB Output is correct
29 Correct 811 ms 1516 KB Output is correct
30 Correct 811 ms 1560 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 82 ms 660 KB Output is correct
5 Correct 355 ms 1076 KB Output is correct
6 Correct 802 ms 1588 KB Output is correct
7 Correct 829 ms 1516 KB Output is correct
8 Correct 823 ms 1532 KB Output is correct
9 Correct 820 ms 1552 KB Output is correct
10 Correct 804 ms 1452 KB Output is correct
11 Correct 817 ms 1512 KB Output is correct
12 Correct 822 ms 1448 KB Output is correct
13 Correct 812 ms 1636 KB Output is correct
14 Correct 816 ms 1428 KB Output is correct
15 Correct 804 ms 1496 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 2 ms 340 KB Output is correct
19 Correct 76 ms 592 KB Output is correct
20 Correct 356 ms 1036 KB Output is correct
21 Correct 815 ms 1464 KB Output is correct
22 Correct 823 ms 1480 KB Output is correct
23 Correct 828 ms 1648 KB Output is correct
24 Correct 804 ms 1380 KB Output is correct
25 Correct 809 ms 1592 KB Output is correct
26 Correct 816 ms 1484 KB Output is correct
27 Correct 814 ms 1504 KB Output is correct
28 Correct 836 ms 1400 KB Output is correct
29 Correct 811 ms 1516 KB Output is correct
30 Correct 811 ms 1560 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 2 ms 340 KB Output is correct
35 Correct 2 ms 340 KB Output is correct
36 Correct 2 ms 344 KB Output is correct
37 Correct 17 ms 480 KB Output is correct
38 Correct 17 ms 528 KB Output is correct
39 Correct 82 ms 632 KB Output is correct
40 Correct 365 ms 1020 KB Output is correct
41 Correct 826 ms 1440 KB Output is correct
42 Correct 824 ms 1580 KB Output is correct
43 Correct 819 ms 1472 KB Output is correct
44 Correct 838 ms 1424 KB Output is correct
45 Correct 825 ms 1492 KB Output is correct
46 Correct 819 ms 1520 KB Output is correct
47 Correct 814 ms 1392 KB Output is correct
48 Correct 829 ms 1448 KB Output is correct
49 Correct 831 ms 1420 KB Output is correct
50 Correct 829 ms 1540 KB Output is correct
51 Correct 823 ms 1524 KB Output is correct
52 Correct 827 ms 1600 KB Output is correct
53 Correct 808 ms 1520 KB Output is correct
54 Correct 817 ms 1604 KB Output is correct
55 Correct 819 ms 1412 KB Output is correct
56 Correct 772 ms 1468 KB Output is correct
57 Correct 828 ms 1560 KB Output is correct
58 Correct 853 ms 1532 KB Output is correct
59 Correct 833 ms 1468 KB Output is correct
60 Correct 839 ms 1484 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 2 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 2 ms 340 KB Output is correct
14 Correct 82 ms 660 KB Output is correct
15 Correct 355 ms 1076 KB Output is correct
16 Correct 802 ms 1588 KB Output is correct
17 Correct 829 ms 1516 KB Output is correct
18 Correct 823 ms 1532 KB Output is correct
19 Correct 820 ms 1552 KB Output is correct
20 Correct 804 ms 1452 KB Output is correct
21 Correct 817 ms 1512 KB Output is correct
22 Correct 822 ms 1448 KB Output is correct
23 Correct 812 ms 1636 KB Output is correct
24 Correct 816 ms 1428 KB Output is correct
25 Correct 804 ms 1496 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 2 ms 340 KB Output is correct
29 Correct 76 ms 592 KB Output is correct
30 Correct 356 ms 1036 KB Output is correct
31 Correct 815 ms 1464 KB Output is correct
32 Correct 823 ms 1480 KB Output is correct
33 Correct 828 ms 1648 KB Output is correct
34 Correct 804 ms 1380 KB Output is correct
35 Correct 809 ms 1592 KB Output is correct
36 Correct 816 ms 1484 KB Output is correct
37 Correct 814 ms 1504 KB Output is correct
38 Correct 836 ms 1400 KB Output is correct
39 Correct 811 ms 1516 KB Output is correct
40 Correct 811 ms 1560 KB Output is correct
41 Correct 1 ms 340 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 2 ms 340 KB Output is correct
45 Correct 2 ms 340 KB Output is correct
46 Correct 2 ms 344 KB Output is correct
47 Correct 17 ms 480 KB Output is correct
48 Correct 17 ms 528 KB Output is correct
49 Correct 82 ms 632 KB Output is correct
50 Correct 365 ms 1020 KB Output is correct
51 Correct 826 ms 1440 KB Output is correct
52 Correct 824 ms 1580 KB Output is correct
53 Correct 819 ms 1472 KB Output is correct
54 Correct 838 ms 1424 KB Output is correct
55 Correct 825 ms 1492 KB Output is correct
56 Correct 819 ms 1520 KB Output is correct
57 Correct 814 ms 1392 KB Output is correct
58 Correct 829 ms 1448 KB Output is correct
59 Correct 831 ms 1420 KB Output is correct
60 Correct 829 ms 1540 KB Output is correct
61 Correct 823 ms 1524 KB Output is correct
62 Correct 827 ms 1600 KB Output is correct
63 Correct 808 ms 1520 KB Output is correct
64 Correct 817 ms 1604 KB Output is correct
65 Correct 819 ms 1412 KB Output is correct
66 Correct 772 ms 1468 KB Output is correct
67 Correct 828 ms 1560 KB Output is correct
68 Correct 853 ms 1532 KB Output is correct
69 Correct 833 ms 1468 KB Output is correct
70 Correct 839 ms 1484 KB Output is correct
71 Correct 17 ms 468 KB Output is correct
72 Correct 19 ms 536 KB Output is correct
73 Correct 18 ms 512 KB Output is correct
74 Correct 18 ms 468 KB Output is correct
75 Correct 19 ms 516 KB Output is correct
76 Correct 83 ms 720 KB Output is correct
77 Correct 76 ms 796 KB Output is correct
78 Correct 86 ms 720 KB Output is correct
79 Correct 85 ms 736 KB Output is correct
80 Correct 85 ms 716 KB Output is correct
81 Correct 362 ms 1220 KB Output is correct
82 Correct 360 ms 1228 KB Output is correct
83 Correct 353 ms 1188 KB Output is correct
84 Correct 356 ms 1236 KB Output is correct
85 Correct 352 ms 1208 KB Output is correct
86 Correct 365 ms 1272 KB Output is correct
87 Correct 349 ms 1424 KB Output is correct
88 Correct 360 ms 1320 KB Output is correct
89 Correct 353 ms 1268 KB Output is correct
90 Correct 360 ms 1384 KB Output is correct
91 Correct 842 ms 2508 KB Output is correct
92 Correct 850 ms 2460 KB Output is correct
93 Correct 827 ms 2632 KB Output is correct
94 Correct 839 ms 2660 KB Output is correct
95 Correct 861 ms 2548 KB Output is correct
96 Correct 851 ms 3436 KB Output is correct
97 Correct 862 ms 3460 KB Output is correct
98 Correct 856 ms 3516 KB Output is correct
99 Correct 805 ms 3572 KB Output is correct
100 Correct 853 ms 3372 KB Output is correct
101 Correct 846 ms 3352 KB Output is correct
102 Correct 850 ms 3396 KB Output is correct
103 Correct 836 ms 3536 KB Output is correct
104 Correct 861 ms 3564 KB Output is correct
105 Correct 844 ms 3408 KB Output is correct
106 Correct 846 ms 3532 KB Output is correct
107 Correct 841 ms 3700 KB Output is correct
108 Correct 838 ms 3776 KB Output is correct
109 Correct 841 ms 3760 KB Output is correct
110 Correct 834 ms 3716 KB Output is correct
111 Correct 836 ms 3664 KB Output is correct
112 Correct 859 ms 3652 KB Output is correct
113 Correct 838 ms 3636 KB Output is correct
114 Correct 858 ms 3752 KB Output is correct
115 Correct 846 ms 3704 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 2 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 2 ms 340 KB Output is correct
14 Correct 82 ms 660 KB Output is correct
15 Correct 355 ms 1076 KB Output is correct
16 Correct 802 ms 1588 KB Output is correct
17 Correct 829 ms 1516 KB Output is correct
18 Correct 823 ms 1532 KB Output is correct
19 Correct 820 ms 1552 KB Output is correct
20 Correct 804 ms 1452 KB Output is correct
21 Correct 817 ms 1512 KB Output is correct
22 Correct 822 ms 1448 KB Output is correct
23 Correct 812 ms 1636 KB Output is correct
24 Correct 816 ms 1428 KB Output is correct
25 Correct 804 ms 1496 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 2 ms 340 KB Output is correct
29 Correct 76 ms 592 KB Output is correct
30 Correct 356 ms 1036 KB Output is correct
31 Correct 815 ms 1464 KB Output is correct
32 Correct 823 ms 1480 KB Output is correct
33 Correct 828 ms 1648 KB Output is correct
34 Correct 804 ms 1380 KB Output is correct
35 Correct 809 ms 1592 KB Output is correct
36 Correct 816 ms 1484 KB Output is correct
37 Correct 814 ms 1504 KB Output is correct
38 Correct 836 ms 1400 KB Output is correct
39 Correct 811 ms 1516 KB Output is correct
40 Correct 811 ms 1560 KB Output is correct
41 Correct 1 ms 340 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 2 ms 340 KB Output is correct
45 Correct 2 ms 340 KB Output is correct
46 Correct 2 ms 344 KB Output is correct
47 Correct 17 ms 480 KB Output is correct
48 Correct 17 ms 528 KB Output is correct
49 Correct 82 ms 632 KB Output is correct
50 Correct 365 ms 1020 KB Output is correct
51 Correct 826 ms 1440 KB Output is correct
52 Correct 824 ms 1580 KB Output is correct
53 Correct 819 ms 1472 KB Output is correct
54 Correct 838 ms 1424 KB Output is correct
55 Correct 825 ms 1492 KB Output is correct
56 Correct 819 ms 1520 KB Output is correct
57 Correct 814 ms 1392 KB Output is correct
58 Correct 829 ms 1448 KB Output is correct
59 Correct 831 ms 1420 KB Output is correct
60 Correct 829 ms 1540 KB Output is correct
61 Correct 823 ms 1524 KB Output is correct
62 Correct 827 ms 1600 KB Output is correct
63 Correct 808 ms 1520 KB Output is correct
64 Correct 817 ms 1604 KB Output is correct
65 Correct 819 ms 1412 KB Output is correct
66 Correct 772 ms 1468 KB Output is correct
67 Correct 828 ms 1560 KB Output is correct
68 Correct 853 ms 1532 KB Output is correct
69 Correct 833 ms 1468 KB Output is correct
70 Correct 839 ms 1484 KB Output is correct
71 Correct 17 ms 468 KB Output is correct
72 Correct 19 ms 536 KB Output is correct
73 Correct 18 ms 512 KB Output is correct
74 Correct 18 ms 468 KB Output is correct
75 Correct 19 ms 516 KB Output is correct
76 Correct 83 ms 720 KB Output is correct
77 Correct 76 ms 796 KB Output is correct
78 Correct 86 ms 720 KB Output is correct
79 Correct 85 ms 736 KB Output is correct
80 Correct 85 ms 716 KB Output is correct
81 Correct 362 ms 1220 KB Output is correct
82 Correct 360 ms 1228 KB Output is correct
83 Correct 353 ms 1188 KB Output is correct
84 Correct 356 ms 1236 KB Output is correct
85 Correct 352 ms 1208 KB Output is correct
86 Correct 365 ms 1272 KB Output is correct
87 Correct 349 ms 1424 KB Output is correct
88 Correct 360 ms 1320 KB Output is correct
89 Correct 353 ms 1268 KB Output is correct
90 Correct 360 ms 1384 KB Output is correct
91 Correct 842 ms 2508 KB Output is correct
92 Correct 850 ms 2460 KB Output is correct
93 Correct 827 ms 2632 KB Output is correct
94 Correct 839 ms 2660 KB Output is correct
95 Correct 861 ms 2548 KB Output is correct
96 Correct 851 ms 3436 KB Output is correct
97 Correct 862 ms 3460 KB Output is correct
98 Correct 856 ms 3516 KB Output is correct
99 Correct 805 ms 3572 KB Output is correct
100 Correct 853 ms 3372 KB Output is correct
101 Correct 846 ms 3352 KB Output is correct
102 Correct 850 ms 3396 KB Output is correct
103 Correct 836 ms 3536 KB Output is correct
104 Correct 861 ms 3564 KB Output is correct
105 Correct 844 ms 3408 KB Output is correct
106 Correct 846 ms 3532 KB Output is correct
107 Correct 841 ms 3700 KB Output is correct
108 Correct 838 ms 3776 KB Output is correct
109 Correct 841 ms 3760 KB Output is correct
110 Correct 834 ms 3716 KB Output is correct
111 Correct 836 ms 3664 KB Output is correct
112 Correct 859 ms 3652 KB Output is correct
113 Correct 838 ms 3636 KB Output is correct
114 Correct 858 ms 3752 KB Output is correct
115 Correct 846 ms 3704 KB Output is correct
116 Incorrect 2 ms 340 KB Output isn't correct
117 Halted 0 ms 0 KB -