#include <bits/stdc++.h>
using i64 = long long;
#ifdef DEBUG
#include "/home/ahmetalp/Desktop/Workplace/debug.h"
#else
#define debug(...) void(23)
#endif
constexpr int max_A = int(3E5) + 5;
int cnt[max_A];
i64 calc(std::vector<i64> x) {
int n = int(x.size());
i64 ans = 0;
for (int i = 0; i < n; ++i) {
ans += x[i] * (x[i] + 1) / 2;
for (int j = i + 1; j < n; ++j) {
ans += x[i] * x[j] * (j - i + 1);
}
}
return ans;
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int N, Q;
std::cin >> N >> Q;
std::vector<int> A(N);
for (int i = 0; i < N; ++i) {
std::cin >> A[i];
}
std::vector<int> L(Q), R(Q);
for (int i = 0; i < Q; ++i) {
std::cin >> L[i] >> R[i];
}
for (int i = 0; i < N; ++i) {
++cnt[A[i]];
}
std::vector<i64> x;
for (int i = 0; i < max_A; ++i) {
if (cnt[i] != 0) {
x.emplace_back(cnt[i]);
}
}
int n = int(x.size());
std::sort(x.begin(), x.end());
std::vector<i64> w(n);
int l = 0, r = n - 1;
for (int i = 0; i < n; ++i) {
if (~i & 1) w[l++] = x[i];
else w[r--] = x[i];
}
debug(w);
i64 ans = calc(w);
std::cout << ans << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
2 ms |
336 KB |
Output is correct |
4 |
Correct |
6 ms |
848 KB |
Output is correct |
5 |
Correct |
9 ms |
1616 KB |
Output is correct |
6 |
Correct |
14 ms |
2128 KB |
Output is correct |
7 |
Correct |
14 ms |
2128 KB |
Output is correct |
8 |
Correct |
12 ms |
1616 KB |
Output is correct |
9 |
Correct |
12 ms |
1868 KB |
Output is correct |
10 |
Correct |
13 ms |
2056 KB |
Output is correct |
11 |
Correct |
18 ms |
1616 KB |
Output is correct |
12 |
Correct |
14 ms |
1924 KB |
Output is correct |
13 |
Correct |
12 ms |
1616 KB |
Output is correct |
14 |
Correct |
13 ms |
2128 KB |
Output is correct |
15 |
Correct |
14 ms |
2128 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
2 ms |
336 KB |
Output is correct |
4 |
Correct |
6 ms |
848 KB |
Output is correct |
5 |
Correct |
9 ms |
1616 KB |
Output is correct |
6 |
Correct |
14 ms |
2128 KB |
Output is correct |
7 |
Correct |
14 ms |
2128 KB |
Output is correct |
8 |
Correct |
12 ms |
1616 KB |
Output is correct |
9 |
Correct |
12 ms |
1868 KB |
Output is correct |
10 |
Correct |
13 ms |
2056 KB |
Output is correct |
11 |
Correct |
18 ms |
1616 KB |
Output is correct |
12 |
Correct |
14 ms |
1924 KB |
Output is correct |
13 |
Correct |
12 ms |
1616 KB |
Output is correct |
14 |
Correct |
13 ms |
2128 KB |
Output is correct |
15 |
Correct |
14 ms |
2128 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
2 ms |
504 KB |
Output is correct |
19 |
Correct |
6 ms |
1104 KB |
Output is correct |
20 |
Correct |
9 ms |
1104 KB |
Output is correct |
21 |
Correct |
13 ms |
1616 KB |
Output is correct |
22 |
Correct |
13 ms |
1616 KB |
Output is correct |
23 |
Correct |
18 ms |
2384 KB |
Output is correct |
24 |
Correct |
13 ms |
2552 KB |
Output is correct |
25 |
Correct |
13 ms |
2552 KB |
Output is correct |
26 |
Correct |
14 ms |
2128 KB |
Output is correct |
27 |
Correct |
13 ms |
2384 KB |
Output is correct |
28 |
Correct |
13 ms |
2128 KB |
Output is correct |
29 |
Correct |
14 ms |
2384 KB |
Output is correct |
30 |
Correct |
13 ms |
2272 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
2 ms |
336 KB |
Output is correct |
4 |
Correct |
6 ms |
848 KB |
Output is correct |
5 |
Correct |
9 ms |
1616 KB |
Output is correct |
6 |
Correct |
14 ms |
2128 KB |
Output is correct |
7 |
Correct |
14 ms |
2128 KB |
Output is correct |
8 |
Correct |
12 ms |
1616 KB |
Output is correct |
9 |
Correct |
12 ms |
1868 KB |
Output is correct |
10 |
Correct |
13 ms |
2056 KB |
Output is correct |
11 |
Correct |
18 ms |
1616 KB |
Output is correct |
12 |
Correct |
14 ms |
1924 KB |
Output is correct |
13 |
Correct |
12 ms |
1616 KB |
Output is correct |
14 |
Correct |
13 ms |
2128 KB |
Output is correct |
15 |
Correct |
14 ms |
2128 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
2 ms |
504 KB |
Output is correct |
19 |
Correct |
6 ms |
1104 KB |
Output is correct |
20 |
Correct |
9 ms |
1104 KB |
Output is correct |
21 |
Correct |
13 ms |
1616 KB |
Output is correct |
22 |
Correct |
13 ms |
1616 KB |
Output is correct |
23 |
Correct |
18 ms |
2384 KB |
Output is correct |
24 |
Correct |
13 ms |
2552 KB |
Output is correct |
25 |
Correct |
13 ms |
2552 KB |
Output is correct |
26 |
Correct |
14 ms |
2128 KB |
Output is correct |
27 |
Correct |
13 ms |
2384 KB |
Output is correct |
28 |
Correct |
13 ms |
2128 KB |
Output is correct |
29 |
Correct |
14 ms |
2384 KB |
Output is correct |
30 |
Correct |
13 ms |
2272 KB |
Output is correct |
31 |
Correct |
1 ms |
504 KB |
Output is correct |
32 |
Correct |
1 ms |
336 KB |
Output is correct |
33 |
Correct |
1 ms |
336 KB |
Output is correct |
34 |
Correct |
2 ms |
336 KB |
Output is correct |
35 |
Correct |
2 ms |
336 KB |
Output is correct |
36 |
Correct |
2 ms |
504 KB |
Output is correct |
37 |
Correct |
4 ms |
852 KB |
Output is correct |
38 |
Correct |
4 ms |
848 KB |
Output is correct |
39 |
Correct |
6 ms |
1104 KB |
Output is correct |
40 |
Correct |
11 ms |
1616 KB |
Output is correct |
41 |
Correct |
15 ms |
2800 KB |
Output is correct |
42 |
Correct |
17 ms |
2784 KB |
Output is correct |
43 |
Correct |
15 ms |
2384 KB |
Output is correct |
44 |
Correct |
14 ms |
1616 KB |
Output is correct |
45 |
Correct |
15 ms |
2304 KB |
Output is correct |
46 |
Correct |
17 ms |
2376 KB |
Output is correct |
47 |
Correct |
14 ms |
1784 KB |
Output is correct |
48 |
Correct |
15 ms |
1656 KB |
Output is correct |
49 |
Correct |
17 ms |
2444 KB |
Output is correct |
50 |
Correct |
17 ms |
2384 KB |
Output is correct |
51 |
Correct |
16 ms |
2384 KB |
Output is correct |
52 |
Correct |
16 ms |
1784 KB |
Output is correct |
53 |
Correct |
15 ms |
1644 KB |
Output is correct |
54 |
Correct |
15 ms |
1616 KB |
Output is correct |
55 |
Correct |
15 ms |
2652 KB |
Output is correct |
56 |
Correct |
17 ms |
2264 KB |
Output is correct |
57 |
Correct |
21 ms |
1616 KB |
Output is correct |
58 |
Correct |
16 ms |
2456 KB |
Output is correct |
59 |
Correct |
14 ms |
1784 KB |
Output is correct |
60 |
Correct |
20 ms |
2376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
2 ms |
336 KB |
Output is correct |
14 |
Correct |
6 ms |
848 KB |
Output is correct |
15 |
Correct |
9 ms |
1616 KB |
Output is correct |
16 |
Correct |
14 ms |
2128 KB |
Output is correct |
17 |
Correct |
14 ms |
2128 KB |
Output is correct |
18 |
Correct |
12 ms |
1616 KB |
Output is correct |
19 |
Correct |
12 ms |
1868 KB |
Output is correct |
20 |
Correct |
13 ms |
2056 KB |
Output is correct |
21 |
Correct |
18 ms |
1616 KB |
Output is correct |
22 |
Correct |
14 ms |
1924 KB |
Output is correct |
23 |
Correct |
12 ms |
1616 KB |
Output is correct |
24 |
Correct |
13 ms |
2128 KB |
Output is correct |
25 |
Correct |
14 ms |
2128 KB |
Output is correct |
26 |
Correct |
1 ms |
336 KB |
Output is correct |
27 |
Correct |
1 ms |
336 KB |
Output is correct |
28 |
Correct |
2 ms |
504 KB |
Output is correct |
29 |
Correct |
6 ms |
1104 KB |
Output is correct |
30 |
Correct |
9 ms |
1104 KB |
Output is correct |
31 |
Correct |
13 ms |
1616 KB |
Output is correct |
32 |
Correct |
13 ms |
1616 KB |
Output is correct |
33 |
Correct |
18 ms |
2384 KB |
Output is correct |
34 |
Correct |
13 ms |
2552 KB |
Output is correct |
35 |
Correct |
13 ms |
2552 KB |
Output is correct |
36 |
Correct |
14 ms |
2128 KB |
Output is correct |
37 |
Correct |
13 ms |
2384 KB |
Output is correct |
38 |
Correct |
13 ms |
2128 KB |
Output is correct |
39 |
Correct |
14 ms |
2384 KB |
Output is correct |
40 |
Correct |
13 ms |
2272 KB |
Output is correct |
41 |
Correct |
1 ms |
504 KB |
Output is correct |
42 |
Correct |
1 ms |
336 KB |
Output is correct |
43 |
Correct |
1 ms |
336 KB |
Output is correct |
44 |
Correct |
2 ms |
336 KB |
Output is correct |
45 |
Correct |
2 ms |
336 KB |
Output is correct |
46 |
Correct |
2 ms |
504 KB |
Output is correct |
47 |
Correct |
4 ms |
852 KB |
Output is correct |
48 |
Correct |
4 ms |
848 KB |
Output is correct |
49 |
Correct |
6 ms |
1104 KB |
Output is correct |
50 |
Correct |
11 ms |
1616 KB |
Output is correct |
51 |
Correct |
15 ms |
2800 KB |
Output is correct |
52 |
Correct |
17 ms |
2784 KB |
Output is correct |
53 |
Correct |
15 ms |
2384 KB |
Output is correct |
54 |
Correct |
14 ms |
1616 KB |
Output is correct |
55 |
Correct |
15 ms |
2304 KB |
Output is correct |
56 |
Correct |
17 ms |
2376 KB |
Output is correct |
57 |
Correct |
14 ms |
1784 KB |
Output is correct |
58 |
Correct |
15 ms |
1656 KB |
Output is correct |
59 |
Correct |
17 ms |
2444 KB |
Output is correct |
60 |
Correct |
17 ms |
2384 KB |
Output is correct |
61 |
Correct |
16 ms |
2384 KB |
Output is correct |
62 |
Correct |
16 ms |
1784 KB |
Output is correct |
63 |
Correct |
15 ms |
1644 KB |
Output is correct |
64 |
Correct |
15 ms |
1616 KB |
Output is correct |
65 |
Correct |
15 ms |
2652 KB |
Output is correct |
66 |
Correct |
17 ms |
2264 KB |
Output is correct |
67 |
Correct |
21 ms |
1616 KB |
Output is correct |
68 |
Correct |
16 ms |
2456 KB |
Output is correct |
69 |
Correct |
14 ms |
1784 KB |
Output is correct |
70 |
Correct |
20 ms |
2376 KB |
Output is correct |
71 |
Correct |
6 ms |
848 KB |
Output is correct |
72 |
Correct |
5 ms |
592 KB |
Output is correct |
73 |
Correct |
5 ms |
760 KB |
Output is correct |
74 |
Correct |
7 ms |
848 KB |
Output is correct |
75 |
Correct |
5 ms |
640 KB |
Output is correct |
76 |
Correct |
20 ms |
1492 KB |
Output is correct |
77 |
Correct |
15 ms |
1360 KB |
Output is correct |
78 |
Correct |
16 ms |
1360 KB |
Output is correct |
79 |
Correct |
17 ms |
848 KB |
Output is correct |
80 |
Correct |
16 ms |
1360 KB |
Output is correct |
81 |
Correct |
44 ms |
1360 KB |
Output is correct |
82 |
Correct |
46 ms |
2128 KB |
Output is correct |
83 |
Correct |
46 ms |
2256 KB |
Output is correct |
84 |
Correct |
44 ms |
1372 KB |
Output is correct |
85 |
Correct |
53 ms |
2272 KB |
Output is correct |
86 |
Correct |
159 ms |
2772 KB |
Output is correct |
87 |
Correct |
159 ms |
2516 KB |
Output is correct |
88 |
Correct |
150 ms |
2656 KB |
Output is correct |
89 |
Correct |
147 ms |
2992 KB |
Output is correct |
90 |
Correct |
148 ms |
2772 KB |
Output is correct |
91 |
Correct |
3498 ms |
4512 KB |
Output is correct |
92 |
Correct |
3454 ms |
5548 KB |
Output is correct |
93 |
Correct |
3368 ms |
5536 KB |
Output is correct |
94 |
Correct |
3360 ms |
4300 KB |
Output is correct |
95 |
Correct |
3389 ms |
4512 KB |
Output is correct |
96 |
Execution timed out |
7059 ms |
9416 KB |
Time limit exceeded |
97 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
2 ms |
336 KB |
Output is correct |
14 |
Correct |
6 ms |
848 KB |
Output is correct |
15 |
Correct |
9 ms |
1616 KB |
Output is correct |
16 |
Correct |
14 ms |
2128 KB |
Output is correct |
17 |
Correct |
14 ms |
2128 KB |
Output is correct |
18 |
Correct |
12 ms |
1616 KB |
Output is correct |
19 |
Correct |
12 ms |
1868 KB |
Output is correct |
20 |
Correct |
13 ms |
2056 KB |
Output is correct |
21 |
Correct |
18 ms |
1616 KB |
Output is correct |
22 |
Correct |
14 ms |
1924 KB |
Output is correct |
23 |
Correct |
12 ms |
1616 KB |
Output is correct |
24 |
Correct |
13 ms |
2128 KB |
Output is correct |
25 |
Correct |
14 ms |
2128 KB |
Output is correct |
26 |
Correct |
1 ms |
336 KB |
Output is correct |
27 |
Correct |
1 ms |
336 KB |
Output is correct |
28 |
Correct |
2 ms |
504 KB |
Output is correct |
29 |
Correct |
6 ms |
1104 KB |
Output is correct |
30 |
Correct |
9 ms |
1104 KB |
Output is correct |
31 |
Correct |
13 ms |
1616 KB |
Output is correct |
32 |
Correct |
13 ms |
1616 KB |
Output is correct |
33 |
Correct |
18 ms |
2384 KB |
Output is correct |
34 |
Correct |
13 ms |
2552 KB |
Output is correct |
35 |
Correct |
13 ms |
2552 KB |
Output is correct |
36 |
Correct |
14 ms |
2128 KB |
Output is correct |
37 |
Correct |
13 ms |
2384 KB |
Output is correct |
38 |
Correct |
13 ms |
2128 KB |
Output is correct |
39 |
Correct |
14 ms |
2384 KB |
Output is correct |
40 |
Correct |
13 ms |
2272 KB |
Output is correct |
41 |
Correct |
1 ms |
504 KB |
Output is correct |
42 |
Correct |
1 ms |
336 KB |
Output is correct |
43 |
Correct |
1 ms |
336 KB |
Output is correct |
44 |
Correct |
2 ms |
336 KB |
Output is correct |
45 |
Correct |
2 ms |
336 KB |
Output is correct |
46 |
Correct |
2 ms |
504 KB |
Output is correct |
47 |
Correct |
4 ms |
852 KB |
Output is correct |
48 |
Correct |
4 ms |
848 KB |
Output is correct |
49 |
Correct |
6 ms |
1104 KB |
Output is correct |
50 |
Correct |
11 ms |
1616 KB |
Output is correct |
51 |
Correct |
15 ms |
2800 KB |
Output is correct |
52 |
Correct |
17 ms |
2784 KB |
Output is correct |
53 |
Correct |
15 ms |
2384 KB |
Output is correct |
54 |
Correct |
14 ms |
1616 KB |
Output is correct |
55 |
Correct |
15 ms |
2304 KB |
Output is correct |
56 |
Correct |
17 ms |
2376 KB |
Output is correct |
57 |
Correct |
14 ms |
1784 KB |
Output is correct |
58 |
Correct |
15 ms |
1656 KB |
Output is correct |
59 |
Correct |
17 ms |
2444 KB |
Output is correct |
60 |
Correct |
17 ms |
2384 KB |
Output is correct |
61 |
Correct |
16 ms |
2384 KB |
Output is correct |
62 |
Correct |
16 ms |
1784 KB |
Output is correct |
63 |
Correct |
15 ms |
1644 KB |
Output is correct |
64 |
Correct |
15 ms |
1616 KB |
Output is correct |
65 |
Correct |
15 ms |
2652 KB |
Output is correct |
66 |
Correct |
17 ms |
2264 KB |
Output is correct |
67 |
Correct |
21 ms |
1616 KB |
Output is correct |
68 |
Correct |
16 ms |
2456 KB |
Output is correct |
69 |
Correct |
14 ms |
1784 KB |
Output is correct |
70 |
Correct |
20 ms |
2376 KB |
Output is correct |
71 |
Correct |
6 ms |
848 KB |
Output is correct |
72 |
Correct |
5 ms |
592 KB |
Output is correct |
73 |
Correct |
5 ms |
760 KB |
Output is correct |
74 |
Correct |
7 ms |
848 KB |
Output is correct |
75 |
Correct |
5 ms |
640 KB |
Output is correct |
76 |
Correct |
20 ms |
1492 KB |
Output is correct |
77 |
Correct |
15 ms |
1360 KB |
Output is correct |
78 |
Correct |
16 ms |
1360 KB |
Output is correct |
79 |
Correct |
17 ms |
848 KB |
Output is correct |
80 |
Correct |
16 ms |
1360 KB |
Output is correct |
81 |
Correct |
44 ms |
1360 KB |
Output is correct |
82 |
Correct |
46 ms |
2128 KB |
Output is correct |
83 |
Correct |
46 ms |
2256 KB |
Output is correct |
84 |
Correct |
44 ms |
1372 KB |
Output is correct |
85 |
Correct |
53 ms |
2272 KB |
Output is correct |
86 |
Correct |
159 ms |
2772 KB |
Output is correct |
87 |
Correct |
159 ms |
2516 KB |
Output is correct |
88 |
Correct |
150 ms |
2656 KB |
Output is correct |
89 |
Correct |
147 ms |
2992 KB |
Output is correct |
90 |
Correct |
148 ms |
2772 KB |
Output is correct |
91 |
Correct |
3498 ms |
4512 KB |
Output is correct |
92 |
Correct |
3454 ms |
5548 KB |
Output is correct |
93 |
Correct |
3368 ms |
5536 KB |
Output is correct |
94 |
Correct |
3360 ms |
4300 KB |
Output is correct |
95 |
Correct |
3389 ms |
4512 KB |
Output is correct |
96 |
Execution timed out |
7059 ms |
9416 KB |
Time limit exceeded |
97 |
Halted |
0 ms |
0 KB |
- |