답안 #474669

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
474669 2021-09-19T10:07:14 Z MilosMilutinovic Diversity (CEOI21_diversity) C++14
64 / 100
67 ms 9064 KB
#include <bits/stdc++.h>

using namespace std;

const int N = 3e5 + 500;

int A[N], n, q, cnt[N], B[N], ans[N];
long long sum[N];

int main(){
        scanf("%d%d", &n, &q);
        for(int i = 1;i <= n;i++){
                scanf("%d", A + i);
                cnt[A[i]]++;
        }
        for(int i = 1;i <= q;i++){
                int l, r; scanf("%d%d", &l, &r);
        }
        iota(B, B + N, 0);
        sort(B, B + N, [&](int i, int j){
                return cnt[i] < cnt[j];
        });
        int l = 1, r = n;
        for(int i = 1;i <= N;i++){
                for(int j = 1;j <= cnt[B[i]];j++){
                        if(i & 1) ans[l++] = B[i];
                        else ans[r--] = B[i];
                }
        }
        int diff = 0;
        sum[n + 1] = 0;
        for(int i = n;i >= 1;i--){
                sum[i] = sum[i + 1] + 1;
                if(i == n || ans[i] != ans[i + 1]) sum[i] += (n - i);
        }
        long long total = 0;
        for(int i = 1;i <= n;i++){
                total += sum[i];
        }
        printf("%lld", total);
        return 0;
}

/*

*/

Compilation message

diversity.cpp: In function 'int main()':
diversity.cpp:30:13: warning: unused variable 'diff' [-Wunused-variable]
   30 |         int diff = 0;
      |             ^~~~
diversity.cpp:11:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 |         scanf("%d%d", &n, &q);
      |         ~~~~~^~~~~~~~~~~~~~~~
diversity.cpp:13:22: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |                 scanf("%d", A + i);
      |                 ~~~~~^~~~~~~~~~~~~
diversity.cpp:17:32: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |                 int l, r; scanf("%d%d", &l, &r);
      |                           ~~~~~^~~~~~~~~~~~~~~~
diversity.cpp:25:43: warning: iteration 300499 invokes undefined behavior [-Waggressive-loop-optimizations]
   25 |                 for(int j = 1;j <= cnt[B[i]];j++){
      |                                        ~~~^
diversity.cpp:24:25: note: within this loop
   24 |         for(int i = 1;i <= N;i++){
      |                       ~~^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 1484 KB Output is correct
2 Correct 7 ms 1484 KB Output is correct
3 Correct 7 ms 1484 KB Output is correct
4 Correct 7 ms 1484 KB Output is correct
5 Correct 8 ms 1488 KB Output is correct
6 Correct 7 ms 1484 KB Output is correct
7 Correct 7 ms 1484 KB Output is correct
8 Correct 7 ms 1484 KB Output is correct
9 Correct 10 ms 1484 KB Output is correct
10 Correct 7 ms 1484 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 1488 KB Output is correct
2 Correct 7 ms 1488 KB Output is correct
3 Correct 8 ms 1612 KB Output is correct
4 Correct 19 ms 3220 KB Output is correct
5 Correct 31 ms 4928 KB Output is correct
6 Correct 41 ms 6732 KB Output is correct
7 Correct 41 ms 6756 KB Output is correct
8 Correct 40 ms 6732 KB Output is correct
9 Correct 41 ms 6724 KB Output is correct
10 Correct 42 ms 6812 KB Output is correct
11 Correct 40 ms 6724 KB Output is correct
12 Correct 40 ms 6756 KB Output is correct
13 Correct 42 ms 6724 KB Output is correct
14 Correct 40 ms 6672 KB Output is correct
15 Correct 40 ms 6720 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 1488 KB Output is correct
2 Correct 7 ms 1488 KB Output is correct
3 Correct 8 ms 1612 KB Output is correct
4 Correct 19 ms 3220 KB Output is correct
5 Correct 31 ms 4928 KB Output is correct
6 Correct 41 ms 6732 KB Output is correct
7 Correct 41 ms 6756 KB Output is correct
8 Correct 40 ms 6732 KB Output is correct
9 Correct 41 ms 6724 KB Output is correct
10 Correct 42 ms 6812 KB Output is correct
11 Correct 40 ms 6724 KB Output is correct
12 Correct 40 ms 6756 KB Output is correct
13 Correct 42 ms 6724 KB Output is correct
14 Correct 40 ms 6672 KB Output is correct
15 Correct 40 ms 6720 KB Output is correct
16 Correct 8 ms 1484 KB Output is correct
17 Correct 8 ms 1484 KB Output is correct
18 Correct 11 ms 1676 KB Output is correct
19 Correct 22 ms 3188 KB Output is correct
20 Correct 30 ms 5032 KB Output is correct
21 Correct 41 ms 6880 KB Output is correct
22 Correct 41 ms 6984 KB Output is correct
23 Correct 41 ms 6948 KB Output is correct
24 Correct 41 ms 6932 KB Output is correct
25 Correct 42 ms 6876 KB Output is correct
26 Correct 41 ms 6856 KB Output is correct
27 Correct 42 ms 6852 KB Output is correct
28 Correct 41 ms 6828 KB Output is correct
29 Correct 41 ms 6836 KB Output is correct
30 Correct 41 ms 6884 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 1488 KB Output is correct
2 Correct 7 ms 1488 KB Output is correct
3 Correct 8 ms 1612 KB Output is correct
4 Correct 19 ms 3220 KB Output is correct
5 Correct 31 ms 4928 KB Output is correct
6 Correct 41 ms 6732 KB Output is correct
7 Correct 41 ms 6756 KB Output is correct
8 Correct 40 ms 6732 KB Output is correct
9 Correct 41 ms 6724 KB Output is correct
10 Correct 42 ms 6812 KB Output is correct
11 Correct 40 ms 6724 KB Output is correct
12 Correct 40 ms 6756 KB Output is correct
13 Correct 42 ms 6724 KB Output is correct
14 Correct 40 ms 6672 KB Output is correct
15 Correct 40 ms 6720 KB Output is correct
16 Correct 8 ms 1484 KB Output is correct
17 Correct 8 ms 1484 KB Output is correct
18 Correct 11 ms 1676 KB Output is correct
19 Correct 22 ms 3188 KB Output is correct
20 Correct 30 ms 5032 KB Output is correct
21 Correct 41 ms 6880 KB Output is correct
22 Correct 41 ms 6984 KB Output is correct
23 Correct 41 ms 6948 KB Output is correct
24 Correct 41 ms 6932 KB Output is correct
25 Correct 42 ms 6876 KB Output is correct
26 Correct 41 ms 6856 KB Output is correct
27 Correct 42 ms 6852 KB Output is correct
28 Correct 41 ms 6828 KB Output is correct
29 Correct 41 ms 6836 KB Output is correct
30 Correct 41 ms 6884 KB Output is correct
31 Correct 7 ms 1488 KB Output is correct
32 Correct 7 ms 1484 KB Output is correct
33 Correct 7 ms 1492 KB Output is correct
34 Correct 9 ms 1612 KB Output is correct
35 Correct 10 ms 1612 KB Output is correct
36 Correct 8 ms 1612 KB Output is correct
37 Correct 13 ms 2380 KB Output is correct
38 Correct 13 ms 2380 KB Output is correct
39 Correct 19 ms 3344 KB Output is correct
40 Correct 30 ms 5328 KB Output is correct
41 Correct 44 ms 7304 KB Output is correct
42 Correct 44 ms 7284 KB Output is correct
43 Correct 41 ms 7280 KB Output is correct
44 Correct 41 ms 7200 KB Output is correct
45 Correct 43 ms 7236 KB Output is correct
46 Correct 41 ms 7216 KB Output is correct
47 Correct 42 ms 7304 KB Output is correct
48 Correct 41 ms 7240 KB Output is correct
49 Correct 43 ms 7236 KB Output is correct
50 Correct 41 ms 7236 KB Output is correct
51 Correct 41 ms 7236 KB Output is correct
52 Correct 43 ms 7364 KB Output is correct
53 Correct 46 ms 7212 KB Output is correct
54 Correct 42 ms 7276 KB Output is correct
55 Correct 43 ms 7268 KB Output is correct
56 Correct 42 ms 7240 KB Output is correct
57 Correct 41 ms 7192 KB Output is correct
58 Correct 41 ms 7232 KB Output is correct
59 Correct 41 ms 7264 KB Output is correct
60 Correct 45 ms 7256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 1484 KB Output is correct
2 Correct 7 ms 1484 KB Output is correct
3 Correct 7 ms 1484 KB Output is correct
4 Correct 7 ms 1484 KB Output is correct
5 Correct 8 ms 1488 KB Output is correct
6 Correct 7 ms 1484 KB Output is correct
7 Correct 7 ms 1484 KB Output is correct
8 Correct 7 ms 1484 KB Output is correct
9 Correct 10 ms 1484 KB Output is correct
10 Correct 7 ms 1484 KB Output is correct
11 Correct 9 ms 1488 KB Output is correct
12 Correct 7 ms 1488 KB Output is correct
13 Correct 8 ms 1612 KB Output is correct
14 Correct 19 ms 3220 KB Output is correct
15 Correct 31 ms 4928 KB Output is correct
16 Correct 41 ms 6732 KB Output is correct
17 Correct 41 ms 6756 KB Output is correct
18 Correct 40 ms 6732 KB Output is correct
19 Correct 41 ms 6724 KB Output is correct
20 Correct 42 ms 6812 KB Output is correct
21 Correct 40 ms 6724 KB Output is correct
22 Correct 40 ms 6756 KB Output is correct
23 Correct 42 ms 6724 KB Output is correct
24 Correct 40 ms 6672 KB Output is correct
25 Correct 40 ms 6720 KB Output is correct
26 Correct 8 ms 1484 KB Output is correct
27 Correct 8 ms 1484 KB Output is correct
28 Correct 11 ms 1676 KB Output is correct
29 Correct 22 ms 3188 KB Output is correct
30 Correct 30 ms 5032 KB Output is correct
31 Correct 41 ms 6880 KB Output is correct
32 Correct 41 ms 6984 KB Output is correct
33 Correct 41 ms 6948 KB Output is correct
34 Correct 41 ms 6932 KB Output is correct
35 Correct 42 ms 6876 KB Output is correct
36 Correct 41 ms 6856 KB Output is correct
37 Correct 42 ms 6852 KB Output is correct
38 Correct 41 ms 6828 KB Output is correct
39 Correct 41 ms 6836 KB Output is correct
40 Correct 41 ms 6884 KB Output is correct
41 Correct 7 ms 1488 KB Output is correct
42 Correct 7 ms 1484 KB Output is correct
43 Correct 7 ms 1492 KB Output is correct
44 Correct 9 ms 1612 KB Output is correct
45 Correct 10 ms 1612 KB Output is correct
46 Correct 8 ms 1612 KB Output is correct
47 Correct 13 ms 2380 KB Output is correct
48 Correct 13 ms 2380 KB Output is correct
49 Correct 19 ms 3344 KB Output is correct
50 Correct 30 ms 5328 KB Output is correct
51 Correct 44 ms 7304 KB Output is correct
52 Correct 44 ms 7284 KB Output is correct
53 Correct 41 ms 7280 KB Output is correct
54 Correct 41 ms 7200 KB Output is correct
55 Correct 43 ms 7236 KB Output is correct
56 Correct 41 ms 7216 KB Output is correct
57 Correct 42 ms 7304 KB Output is correct
58 Correct 41 ms 7240 KB Output is correct
59 Correct 43 ms 7236 KB Output is correct
60 Correct 41 ms 7236 KB Output is correct
61 Correct 41 ms 7236 KB Output is correct
62 Correct 43 ms 7364 KB Output is correct
63 Correct 46 ms 7212 KB Output is correct
64 Correct 42 ms 7276 KB Output is correct
65 Correct 43 ms 7268 KB Output is correct
66 Correct 42 ms 7240 KB Output is correct
67 Correct 41 ms 7192 KB Output is correct
68 Correct 41 ms 7232 KB Output is correct
69 Correct 41 ms 7264 KB Output is correct
70 Correct 45 ms 7256 KB Output is correct
71 Correct 18 ms 2492 KB Output is correct
72 Correct 14 ms 2508 KB Output is correct
73 Correct 18 ms 2508 KB Output is correct
74 Correct 14 ms 2416 KB Output is correct
75 Correct 17 ms 2380 KB Output is correct
76 Correct 20 ms 3448 KB Output is correct
77 Correct 20 ms 3532 KB Output is correct
78 Correct 20 ms 3472 KB Output is correct
79 Correct 20 ms 3532 KB Output is correct
80 Correct 20 ms 3500 KB Output is correct
81 Correct 32 ms 5484 KB Output is correct
82 Correct 34 ms 5556 KB Output is correct
83 Correct 31 ms 5524 KB Output is correct
84 Correct 32 ms 5464 KB Output is correct
85 Correct 33 ms 5476 KB Output is correct
86 Correct 34 ms 5728 KB Output is correct
87 Correct 35 ms 5620 KB Output is correct
88 Correct 34 ms 5688 KB Output is correct
89 Correct 35 ms 5732 KB Output is correct
90 Correct 34 ms 5684 KB Output is correct
91 Correct 51 ms 8260 KB Output is correct
92 Correct 67 ms 8184 KB Output is correct
93 Correct 49 ms 8208 KB Output is correct
94 Correct 49 ms 8172 KB Output is correct
95 Correct 50 ms 8252 KB Output is correct
96 Correct 56 ms 8748 KB Output is correct
97 Correct 56 ms 8800 KB Output is correct
98 Correct 57 ms 8792 KB Output is correct
99 Correct 58 ms 8764 KB Output is correct
100 Correct 58 ms 8832 KB Output is correct
101 Correct 56 ms 8788 KB Output is correct
102 Correct 55 ms 8836 KB Output is correct
103 Correct 55 ms 8772 KB Output is correct
104 Correct 54 ms 8720 KB Output is correct
105 Correct 57 ms 8828 KB Output is correct
106 Correct 57 ms 9064 KB Output is correct
107 Correct 59 ms 9024 KB Output is correct
108 Correct 55 ms 8972 KB Output is correct
109 Correct 56 ms 9028 KB Output is correct
110 Correct 56 ms 9004 KB Output is correct
111 Correct 56 ms 9028 KB Output is correct
112 Correct 55 ms 9040 KB Output is correct
113 Correct 55 ms 9056 KB Output is correct
114 Correct 57 ms 8956 KB Output is correct
115 Correct 54 ms 9056 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 1484 KB Output is correct
2 Correct 7 ms 1484 KB Output is correct
3 Correct 7 ms 1484 KB Output is correct
4 Correct 7 ms 1484 KB Output is correct
5 Correct 8 ms 1488 KB Output is correct
6 Correct 7 ms 1484 KB Output is correct
7 Correct 7 ms 1484 KB Output is correct
8 Correct 7 ms 1484 KB Output is correct
9 Correct 10 ms 1484 KB Output is correct
10 Correct 7 ms 1484 KB Output is correct
11 Correct 9 ms 1488 KB Output is correct
12 Correct 7 ms 1488 KB Output is correct
13 Correct 8 ms 1612 KB Output is correct
14 Correct 19 ms 3220 KB Output is correct
15 Correct 31 ms 4928 KB Output is correct
16 Correct 41 ms 6732 KB Output is correct
17 Correct 41 ms 6756 KB Output is correct
18 Correct 40 ms 6732 KB Output is correct
19 Correct 41 ms 6724 KB Output is correct
20 Correct 42 ms 6812 KB Output is correct
21 Correct 40 ms 6724 KB Output is correct
22 Correct 40 ms 6756 KB Output is correct
23 Correct 42 ms 6724 KB Output is correct
24 Correct 40 ms 6672 KB Output is correct
25 Correct 40 ms 6720 KB Output is correct
26 Correct 8 ms 1484 KB Output is correct
27 Correct 8 ms 1484 KB Output is correct
28 Correct 11 ms 1676 KB Output is correct
29 Correct 22 ms 3188 KB Output is correct
30 Correct 30 ms 5032 KB Output is correct
31 Correct 41 ms 6880 KB Output is correct
32 Correct 41 ms 6984 KB Output is correct
33 Correct 41 ms 6948 KB Output is correct
34 Correct 41 ms 6932 KB Output is correct
35 Correct 42 ms 6876 KB Output is correct
36 Correct 41 ms 6856 KB Output is correct
37 Correct 42 ms 6852 KB Output is correct
38 Correct 41 ms 6828 KB Output is correct
39 Correct 41 ms 6836 KB Output is correct
40 Correct 41 ms 6884 KB Output is correct
41 Correct 7 ms 1488 KB Output is correct
42 Correct 7 ms 1484 KB Output is correct
43 Correct 7 ms 1492 KB Output is correct
44 Correct 9 ms 1612 KB Output is correct
45 Correct 10 ms 1612 KB Output is correct
46 Correct 8 ms 1612 KB Output is correct
47 Correct 13 ms 2380 KB Output is correct
48 Correct 13 ms 2380 KB Output is correct
49 Correct 19 ms 3344 KB Output is correct
50 Correct 30 ms 5328 KB Output is correct
51 Correct 44 ms 7304 KB Output is correct
52 Correct 44 ms 7284 KB Output is correct
53 Correct 41 ms 7280 KB Output is correct
54 Correct 41 ms 7200 KB Output is correct
55 Correct 43 ms 7236 KB Output is correct
56 Correct 41 ms 7216 KB Output is correct
57 Correct 42 ms 7304 KB Output is correct
58 Correct 41 ms 7240 KB Output is correct
59 Correct 43 ms 7236 KB Output is correct
60 Correct 41 ms 7236 KB Output is correct
61 Correct 41 ms 7236 KB Output is correct
62 Correct 43 ms 7364 KB Output is correct
63 Correct 46 ms 7212 KB Output is correct
64 Correct 42 ms 7276 KB Output is correct
65 Correct 43 ms 7268 KB Output is correct
66 Correct 42 ms 7240 KB Output is correct
67 Correct 41 ms 7192 KB Output is correct
68 Correct 41 ms 7232 KB Output is correct
69 Correct 41 ms 7264 KB Output is correct
70 Correct 45 ms 7256 KB Output is correct
71 Correct 18 ms 2492 KB Output is correct
72 Correct 14 ms 2508 KB Output is correct
73 Correct 18 ms 2508 KB Output is correct
74 Correct 14 ms 2416 KB Output is correct
75 Correct 17 ms 2380 KB Output is correct
76 Correct 20 ms 3448 KB Output is correct
77 Correct 20 ms 3532 KB Output is correct
78 Correct 20 ms 3472 KB Output is correct
79 Correct 20 ms 3532 KB Output is correct
80 Correct 20 ms 3500 KB Output is correct
81 Correct 32 ms 5484 KB Output is correct
82 Correct 34 ms 5556 KB Output is correct
83 Correct 31 ms 5524 KB Output is correct
84 Correct 32 ms 5464 KB Output is correct
85 Correct 33 ms 5476 KB Output is correct
86 Correct 34 ms 5728 KB Output is correct
87 Correct 35 ms 5620 KB Output is correct
88 Correct 34 ms 5688 KB Output is correct
89 Correct 35 ms 5732 KB Output is correct
90 Correct 34 ms 5684 KB Output is correct
91 Correct 51 ms 8260 KB Output is correct
92 Correct 67 ms 8184 KB Output is correct
93 Correct 49 ms 8208 KB Output is correct
94 Correct 49 ms 8172 KB Output is correct
95 Correct 50 ms 8252 KB Output is correct
96 Correct 56 ms 8748 KB Output is correct
97 Correct 56 ms 8800 KB Output is correct
98 Correct 57 ms 8792 KB Output is correct
99 Correct 58 ms 8764 KB Output is correct
100 Correct 58 ms 8832 KB Output is correct
101 Correct 56 ms 8788 KB Output is correct
102 Correct 55 ms 8836 KB Output is correct
103 Correct 55 ms 8772 KB Output is correct
104 Correct 54 ms 8720 KB Output is correct
105 Correct 57 ms 8828 KB Output is correct
106 Correct 57 ms 9064 KB Output is correct
107 Correct 59 ms 9024 KB Output is correct
108 Correct 55 ms 8972 KB Output is correct
109 Correct 56 ms 9028 KB Output is correct
110 Correct 56 ms 9004 KB Output is correct
111 Correct 56 ms 9028 KB Output is correct
112 Correct 55 ms 9040 KB Output is correct
113 Correct 55 ms 9056 KB Output is correct
114 Correct 57 ms 8956 KB Output is correct
115 Correct 54 ms 9056 KB Output is correct
116 Incorrect 18 ms 2152 KB Output isn't correct
117 Halted 0 ms 0 KB -