# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
920309 | 2024-02-02T12:42:52 Z | vjudge1 | Diversity (CEOI21_diversity) | C++17 | 7000 ms | 7624 KB |
#include <iostream> #include <vector> #include <algorithm> #include <cassert> #include <cstring> #include <set> #warning That's the baby, that's not my baby typedef long long ll; const int NMAX = 3e5; int a[NMAX + 1]; int f[NMAX + 1]; int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(0); int n, q; std::cin >> n >> q; std::vector<int> norm; for (int i = 1; i <= n; i++) { std::cin >> a[i]; norm.push_back(a[i]); } std::sort(norm.begin(), norm.end()); norm.erase(std::unique(norm.begin(), norm.end()), norm.end()); for (int i = 1; i <= n; i++) { a[i] = std::lower_bound(norm.begin(), norm.end(), a[i]) - norm.begin(); } /** 1 * (f[1] + f[2] + ... + f[k]) + 2 * (f[1] * f[2] + f[2] * f[3] + f[3] * f[4] + ... + f[k - 1] * f[k]) + 3 * (f[1] * f[3] + f[2] * f[4] + ...) + ... **/ while (q--) { int l, r; std::cin >> l >> r; std::vector<int> b; memset(f, 0, sizeof(f)); for (int i = l; i <= r; i++) { f[a[i]]++; } std::vector<int> fr; for (int i = 0; i < NMAX; i++) { if (f[i] != 0) { fr.push_back(f[i]); } } std::sort(fr.begin(), fr.end()); ll answer = 0; std::vector<int> frr; for (int i = 0; i < (int) fr.size(); i += 2) { frr.push_back(fr[i]); } int sz = (int) frr.size(); for (int i = 1; i < (int) fr.size(); i += 2) { frr.push_back(fr[i]); } std::reverse(frr.begin() + sz, frr.end()); // for (const auto &x : frr) { // std::cout << x << ' '; // } // std::cout << '\n'; fr = frr; int m = (int) fr.size(); ll add = 0, sum = 0; for (int i = 0; i < m; i++) { ll cur = 0; for (int j = 0; j < i; j++) { cur += (ll) (i - j + 1) * fr[j]; } answer += (ll) fr[i] * cur; } /** for i=0..m-1: for j=0..i-1: cur += (i - j) * fr[j] **/ for (const auto &x : fr) { answer += (ll) x * (x + 1) / 2; } std::cout << answer << '\n'; } return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 2648 KB | Output is correct |
2 | Correct | 1 ms | 2652 KB | Output is correct |
3 | Correct | 1 ms | 2648 KB | Output is correct |
4 | Correct | 1 ms | 2652 KB | Output is correct |
5 | Correct | 1 ms | 2648 KB | Output is correct |
6 | Correct | 2 ms | 2648 KB | Output is correct |
7 | Correct | 1 ms | 2648 KB | Output is correct |
8 | Correct | 1 ms | 2648 KB | Output is correct |
9 | Correct | 1 ms | 2648 KB | Output is correct |
10 | Correct | 2 ms | 2648 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 2648 KB | Output is correct |
2 | Correct | 1 ms | 2648 KB | Output is correct |
3 | Correct | 2 ms | 2648 KB | Output is correct |
4 | Correct | 8 ms | 3292 KB | Output is correct |
5 | Correct | 17 ms | 4056 KB | Output is correct |
6 | Correct | 26 ms | 5080 KB | Output is correct |
7 | Correct | 23 ms | 5080 KB | Output is correct |
8 | Correct | 26 ms | 5076 KB | Output is correct |
9 | Correct | 27 ms | 5076 KB | Output is correct |
10 | Correct | 26 ms | 5080 KB | Output is correct |
11 | Correct | 25 ms | 5076 KB | Output is correct |
12 | Correct | 27 ms | 5076 KB | Output is correct |
13 | Correct | 26 ms | 5076 KB | Output is correct |
14 | Correct | 26 ms | 5076 KB | Output is correct |
15 | Correct | 27 ms | 5196 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 2648 KB | Output is correct |
2 | Correct | 1 ms | 2648 KB | Output is correct |
3 | Correct | 2 ms | 2648 KB | Output is correct |
4 | Correct | 8 ms | 3292 KB | Output is correct |
5 | Correct | 17 ms | 4056 KB | Output is correct |
6 | Correct | 26 ms | 5080 KB | Output is correct |
7 | Correct | 23 ms | 5080 KB | Output is correct |
8 | Correct | 26 ms | 5076 KB | Output is correct |
9 | Correct | 27 ms | 5076 KB | Output is correct |
10 | Correct | 26 ms | 5080 KB | Output is correct |
11 | Correct | 25 ms | 5076 KB | Output is correct |
12 | Correct | 27 ms | 5076 KB | Output is correct |
13 | Correct | 26 ms | 5076 KB | Output is correct |
14 | Correct | 26 ms | 5076 KB | Output is correct |
15 | Correct | 27 ms | 5196 KB | Output is correct |
16 | Correct | 1 ms | 2648 KB | Output is correct |
17 | Correct | 1 ms | 2648 KB | Output is correct |
18 | Correct | 2 ms | 2652 KB | Output is correct |
19 | Correct | 10 ms | 3292 KB | Output is correct |
20 | Correct | 19 ms | 4056 KB | Output is correct |
21 | Correct | 28 ms | 5336 KB | Output is correct |
22 | Correct | 29 ms | 5332 KB | Output is correct |
23 | Correct | 28 ms | 5332 KB | Output is correct |
24 | Correct | 29 ms | 5336 KB | Output is correct |
25 | Correct | 29 ms | 5332 KB | Output is correct |
26 | Correct | 30 ms | 5076 KB | Output is correct |
27 | Correct | 29 ms | 5336 KB | Output is correct |
28 | Correct | 30 ms | 5080 KB | Output is correct |
29 | Correct | 29 ms | 5332 KB | Output is correct |
30 | Correct | 29 ms | 5332 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 2648 KB | Output is correct |
2 | Correct | 1 ms | 2648 KB | Output is correct |
3 | Correct | 2 ms | 2648 KB | Output is correct |
4 | Correct | 8 ms | 3292 KB | Output is correct |
5 | Correct | 17 ms | 4056 KB | Output is correct |
6 | Correct | 26 ms | 5080 KB | Output is correct |
7 | Correct | 23 ms | 5080 KB | Output is correct |
8 | Correct | 26 ms | 5076 KB | Output is correct |
9 | Correct | 27 ms | 5076 KB | Output is correct |
10 | Correct | 26 ms | 5080 KB | Output is correct |
11 | Correct | 25 ms | 5076 KB | Output is correct |
12 | Correct | 27 ms | 5076 KB | Output is correct |
13 | Correct | 26 ms | 5076 KB | Output is correct |
14 | Correct | 26 ms | 5076 KB | Output is correct |
15 | Correct | 27 ms | 5196 KB | Output is correct |
16 | Correct | 1 ms | 2648 KB | Output is correct |
17 | Correct | 1 ms | 2648 KB | Output is correct |
18 | Correct | 2 ms | 2652 KB | Output is correct |
19 | Correct | 10 ms | 3292 KB | Output is correct |
20 | Correct | 19 ms | 4056 KB | Output is correct |
21 | Correct | 28 ms | 5336 KB | Output is correct |
22 | Correct | 29 ms | 5332 KB | Output is correct |
23 | Correct | 28 ms | 5332 KB | Output is correct |
24 | Correct | 29 ms | 5336 KB | Output is correct |
25 | Correct | 29 ms | 5332 KB | Output is correct |
26 | Correct | 30 ms | 5076 KB | Output is correct |
27 | Correct | 29 ms | 5336 KB | Output is correct |
28 | Correct | 30 ms | 5080 KB | Output is correct |
29 | Correct | 29 ms | 5332 KB | Output is correct |
30 | Correct | 29 ms | 5332 KB | Output is correct |
31 | Correct | 1 ms | 2648 KB | Output is correct |
32 | Correct | 1 ms | 2648 KB | Output is correct |
33 | Correct | 1 ms | 2648 KB | Output is correct |
34 | Correct | 2 ms | 2648 KB | Output is correct |
35 | Correct | 2 ms | 2648 KB | Output is correct |
36 | Correct | 3 ms | 2648 KB | Output is correct |
37 | Correct | 8 ms | 3036 KB | Output is correct |
38 | Correct | 9 ms | 3040 KB | Output is correct |
39 | Correct | 16 ms | 3548 KB | Output is correct |
40 | Correct | 30 ms | 4056 KB | Output is correct |
41 | Correct | 45 ms | 5328 KB | Output is correct |
42 | Correct | 44 ms | 5252 KB | Output is correct |
43 | Correct | 44 ms | 5324 KB | Output is correct |
44 | Correct | 44 ms | 5324 KB | Output is correct |
45 | Correct | 44 ms | 5348 KB | Output is correct |
46 | Correct | 44 ms | 5332 KB | Output is correct |
47 | Correct | 44 ms | 5324 KB | Output is correct |
48 | Correct | 44 ms | 5324 KB | Output is correct |
49 | Correct | 45 ms | 5332 KB | Output is correct |
50 | Correct | 45 ms | 5332 KB | Output is correct |
51 | Correct | 45 ms | 5332 KB | Output is correct |
52 | Correct | 44 ms | 5332 KB | Output is correct |
53 | Correct | 45 ms | 5324 KB | Output is correct |
54 | Correct | 49 ms | 5332 KB | Output is correct |
55 | Correct | 48 ms | 5844 KB | Output is correct |
56 | Correct | 45 ms | 6352 KB | Output is correct |
57 | Correct | 45 ms | 5332 KB | Output is correct |
58 | Correct | 44 ms | 5240 KB | Output is correct |
59 | Correct | 46 ms | 5332 KB | Output is correct |
60 | Correct | 45 ms | 5328 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 2648 KB | Output is correct |
2 | Correct | 1 ms | 2652 KB | Output is correct |
3 | Correct | 1 ms | 2648 KB | Output is correct |
4 | Correct | 1 ms | 2652 KB | Output is correct |
5 | Correct | 1 ms | 2648 KB | Output is correct |
6 | Correct | 2 ms | 2648 KB | Output is correct |
7 | Correct | 1 ms | 2648 KB | Output is correct |
8 | Correct | 1 ms | 2648 KB | Output is correct |
9 | Correct | 1 ms | 2648 KB | Output is correct |
10 | Correct | 2 ms | 2648 KB | Output is correct |
11 | Correct | 1 ms | 2648 KB | Output is correct |
12 | Correct | 1 ms | 2648 KB | Output is correct |
13 | Correct | 2 ms | 2648 KB | Output is correct |
14 | Correct | 8 ms | 3292 KB | Output is correct |
15 | Correct | 17 ms | 4056 KB | Output is correct |
16 | Correct | 26 ms | 5080 KB | Output is correct |
17 | Correct | 23 ms | 5080 KB | Output is correct |
18 | Correct | 26 ms | 5076 KB | Output is correct |
19 | Correct | 27 ms | 5076 KB | Output is correct |
20 | Correct | 26 ms | 5080 KB | Output is correct |
21 | Correct | 25 ms | 5076 KB | Output is correct |
22 | Correct | 27 ms | 5076 KB | Output is correct |
23 | Correct | 26 ms | 5076 KB | Output is correct |
24 | Correct | 26 ms | 5076 KB | Output is correct |
25 | Correct | 27 ms | 5196 KB | Output is correct |
26 | Correct | 1 ms | 2648 KB | Output is correct |
27 | Correct | 1 ms | 2648 KB | Output is correct |
28 | Correct | 2 ms | 2652 KB | Output is correct |
29 | Correct | 10 ms | 3292 KB | Output is correct |
30 | Correct | 19 ms | 4056 KB | Output is correct |
31 | Correct | 28 ms | 5336 KB | Output is correct |
32 | Correct | 29 ms | 5332 KB | Output is correct |
33 | Correct | 28 ms | 5332 KB | Output is correct |
34 | Correct | 29 ms | 5336 KB | Output is correct |
35 | Correct | 29 ms | 5332 KB | Output is correct |
36 | Correct | 30 ms | 5076 KB | Output is correct |
37 | Correct | 29 ms | 5336 KB | Output is correct |
38 | Correct | 30 ms | 5080 KB | Output is correct |
39 | Correct | 29 ms | 5332 KB | Output is correct |
40 | Correct | 29 ms | 5332 KB | Output is correct |
41 | Correct | 1 ms | 2648 KB | Output is correct |
42 | Correct | 1 ms | 2648 KB | Output is correct |
43 | Correct | 1 ms | 2648 KB | Output is correct |
44 | Correct | 2 ms | 2648 KB | Output is correct |
45 | Correct | 2 ms | 2648 KB | Output is correct |
46 | Correct | 3 ms | 2648 KB | Output is correct |
47 | Correct | 8 ms | 3036 KB | Output is correct |
48 | Correct | 9 ms | 3040 KB | Output is correct |
49 | Correct | 16 ms | 3548 KB | Output is correct |
50 | Correct | 30 ms | 4056 KB | Output is correct |
51 | Correct | 45 ms | 5328 KB | Output is correct |
52 | Correct | 44 ms | 5252 KB | Output is correct |
53 | Correct | 44 ms | 5324 KB | Output is correct |
54 | Correct | 44 ms | 5324 KB | Output is correct |
55 | Correct | 44 ms | 5348 KB | Output is correct |
56 | Correct | 44 ms | 5332 KB | Output is correct |
57 | Correct | 44 ms | 5324 KB | Output is correct |
58 | Correct | 44 ms | 5324 KB | Output is correct |
59 | Correct | 45 ms | 5332 KB | Output is correct |
60 | Correct | 45 ms | 5332 KB | Output is correct |
61 | Correct | 45 ms | 5332 KB | Output is correct |
62 | Correct | 44 ms | 5332 KB | Output is correct |
63 | Correct | 45 ms | 5324 KB | Output is correct |
64 | Correct | 49 ms | 5332 KB | Output is correct |
65 | Correct | 48 ms | 5844 KB | Output is correct |
66 | Correct | 45 ms | 6352 KB | Output is correct |
67 | Correct | 45 ms | 5332 KB | Output is correct |
68 | Correct | 44 ms | 5240 KB | Output is correct |
69 | Correct | 46 ms | 5332 KB | Output is correct |
70 | Correct | 45 ms | 5328 KB | Output is correct |
71 | Correct | 11 ms | 3036 KB | Output is correct |
72 | Correct | 10 ms | 3036 KB | Output is correct |
73 | Correct | 10 ms | 3036 KB | Output is correct |
74 | Correct | 10 ms | 3036 KB | Output is correct |
75 | Correct | 10 ms | 3292 KB | Output is correct |
76 | Correct | 30 ms | 3804 KB | Output is correct |
77 | Correct | 27 ms | 3548 KB | Output is correct |
78 | Correct | 27 ms | 3548 KB | Output is correct |
79 | Correct | 27 ms | 3548 KB | Output is correct |
80 | Correct | 27 ms | 3548 KB | Output is correct |
81 | Correct | 71 ms | 4312 KB | Output is correct |
82 | Correct | 70 ms | 4200 KB | Output is correct |
83 | Correct | 72 ms | 4296 KB | Output is correct |
84 | Correct | 71 ms | 4312 KB | Output is correct |
85 | Correct | 72 ms | 4312 KB | Output is correct |
86 | Correct | 174 ms | 4584 KB | Output is correct |
87 | Correct | 172 ms | 4300 KB | Output is correct |
88 | Correct | 176 ms | 4608 KB | Output is correct |
89 | Correct | 177 ms | 4296 KB | Output is correct |
90 | Correct | 172 ms | 4316 KB | Output is correct |
91 | Correct | 3394 ms | 6084 KB | Output is correct |
92 | Correct | 3373 ms | 6084 KB | Output is correct |
93 | Correct | 3358 ms | 6228 KB | Output is correct |
94 | Correct | 3378 ms | 6088 KB | Output is correct |
95 | Correct | 3355 ms | 6088 KB | Output is correct |
96 | Execution timed out | 7039 ms | 7624 KB | Time limit exceeded |
97 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 2648 KB | Output is correct |
2 | Correct | 1 ms | 2652 KB | Output is correct |
3 | Correct | 1 ms | 2648 KB | Output is correct |
4 | Correct | 1 ms | 2652 KB | Output is correct |
5 | Correct | 1 ms | 2648 KB | Output is correct |
6 | Correct | 2 ms | 2648 KB | Output is correct |
7 | Correct | 1 ms | 2648 KB | Output is correct |
8 | Correct | 1 ms | 2648 KB | Output is correct |
9 | Correct | 1 ms | 2648 KB | Output is correct |
10 | Correct | 2 ms | 2648 KB | Output is correct |
11 | Correct | 1 ms | 2648 KB | Output is correct |
12 | Correct | 1 ms | 2648 KB | Output is correct |
13 | Correct | 2 ms | 2648 KB | Output is correct |
14 | Correct | 8 ms | 3292 KB | Output is correct |
15 | Correct | 17 ms | 4056 KB | Output is correct |
16 | Correct | 26 ms | 5080 KB | Output is correct |
17 | Correct | 23 ms | 5080 KB | Output is correct |
18 | Correct | 26 ms | 5076 KB | Output is correct |
19 | Correct | 27 ms | 5076 KB | Output is correct |
20 | Correct | 26 ms | 5080 KB | Output is correct |
21 | Correct | 25 ms | 5076 KB | Output is correct |
22 | Correct | 27 ms | 5076 KB | Output is correct |
23 | Correct | 26 ms | 5076 KB | Output is correct |
24 | Correct | 26 ms | 5076 KB | Output is correct |
25 | Correct | 27 ms | 5196 KB | Output is correct |
26 | Correct | 1 ms | 2648 KB | Output is correct |
27 | Correct | 1 ms | 2648 KB | Output is correct |
28 | Correct | 2 ms | 2652 KB | Output is correct |
29 | Correct | 10 ms | 3292 KB | Output is correct |
30 | Correct | 19 ms | 4056 KB | Output is correct |
31 | Correct | 28 ms | 5336 KB | Output is correct |
32 | Correct | 29 ms | 5332 KB | Output is correct |
33 | Correct | 28 ms | 5332 KB | Output is correct |
34 | Correct | 29 ms | 5336 KB | Output is correct |
35 | Correct | 29 ms | 5332 KB | Output is correct |
36 | Correct | 30 ms | 5076 KB | Output is correct |
37 | Correct | 29 ms | 5336 KB | Output is correct |
38 | Correct | 30 ms | 5080 KB | Output is correct |
39 | Correct | 29 ms | 5332 KB | Output is correct |
40 | Correct | 29 ms | 5332 KB | Output is correct |
41 | Correct | 1 ms | 2648 KB | Output is correct |
42 | Correct | 1 ms | 2648 KB | Output is correct |
43 | Correct | 1 ms | 2648 KB | Output is correct |
44 | Correct | 2 ms | 2648 KB | Output is correct |
45 | Correct | 2 ms | 2648 KB | Output is correct |
46 | Correct | 3 ms | 2648 KB | Output is correct |
47 | Correct | 8 ms | 3036 KB | Output is correct |
48 | Correct | 9 ms | 3040 KB | Output is correct |
49 | Correct | 16 ms | 3548 KB | Output is correct |
50 | Correct | 30 ms | 4056 KB | Output is correct |
51 | Correct | 45 ms | 5328 KB | Output is correct |
52 | Correct | 44 ms | 5252 KB | Output is correct |
53 | Correct | 44 ms | 5324 KB | Output is correct |
54 | Correct | 44 ms | 5324 KB | Output is correct |
55 | Correct | 44 ms | 5348 KB | Output is correct |
56 | Correct | 44 ms | 5332 KB | Output is correct |
57 | Correct | 44 ms | 5324 KB | Output is correct |
58 | Correct | 44 ms | 5324 KB | Output is correct |
59 | Correct | 45 ms | 5332 KB | Output is correct |
60 | Correct | 45 ms | 5332 KB | Output is correct |
61 | Correct | 45 ms | 5332 KB | Output is correct |
62 | Correct | 44 ms | 5332 KB | Output is correct |
63 | Correct | 45 ms | 5324 KB | Output is correct |
64 | Correct | 49 ms | 5332 KB | Output is correct |
65 | Correct | 48 ms | 5844 KB | Output is correct |
66 | Correct | 45 ms | 6352 KB | Output is correct |
67 | Correct | 45 ms | 5332 KB | Output is correct |
68 | Correct | 44 ms | 5240 KB | Output is correct |
69 | Correct | 46 ms | 5332 KB | Output is correct |
70 | Correct | 45 ms | 5328 KB | Output is correct |
71 | Correct | 11 ms | 3036 KB | Output is correct |
72 | Correct | 10 ms | 3036 KB | Output is correct |
73 | Correct | 10 ms | 3036 KB | Output is correct |
74 | Correct | 10 ms | 3036 KB | Output is correct |
75 | Correct | 10 ms | 3292 KB | Output is correct |
76 | Correct | 30 ms | 3804 KB | Output is correct |
77 | Correct | 27 ms | 3548 KB | Output is correct |
78 | Correct | 27 ms | 3548 KB | Output is correct |
79 | Correct | 27 ms | 3548 KB | Output is correct |
80 | Correct | 27 ms | 3548 KB | Output is correct |
81 | Correct | 71 ms | 4312 KB | Output is correct |
82 | Correct | 70 ms | 4200 KB | Output is correct |
83 | Correct | 72 ms | 4296 KB | Output is correct |
84 | Correct | 71 ms | 4312 KB | Output is correct |
85 | Correct | 72 ms | 4312 KB | Output is correct |
86 | Correct | 174 ms | 4584 KB | Output is correct |
87 | Correct | 172 ms | 4300 KB | Output is correct |
88 | Correct | 176 ms | 4608 KB | Output is correct |
89 | Correct | 177 ms | 4296 KB | Output is correct |
90 | Correct | 172 ms | 4316 KB | Output is correct |
91 | Correct | 3394 ms | 6084 KB | Output is correct |
92 | Correct | 3373 ms | 6084 KB | Output is correct |
93 | Correct | 3358 ms | 6228 KB | Output is correct |
94 | Correct | 3378 ms | 6088 KB | Output is correct |
95 | Correct | 3355 ms | 6088 KB | Output is correct |
96 | Execution timed out | 7039 ms | 7624 KB | Time limit exceeded |
97 | Halted | 0 ms | 0 KB | - |