답안 #1097439

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1097439 2024-10-07T11:32:28 Z alexander707070 Diversity (CEOI21_diversity) C++14
64 / 100
44 ms 5468 KB
#include<bits/stdc++.h>
#define MAXN 300007
using namespace std;

int n,a[MAXN],q;

int br[MAXN],maxs,l,r,p[MAXN],len;
long long ans,mult,sum;

int main(){

    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cin>>n>>q;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        br[a[i]]++;

        maxs=max(maxs,a[i]);
    }

    sort(br+1,br+maxs+1);
    for(int i=1;i<=maxs;i++){
        if(br[i]>0)r++;
    }
    r++;
    len=r-1;

    for(int i=1;i<=maxs;i++){
        if(br[i]==0)continue;

        if(i%2==0){
            l++; p[l]=br[i];
        }else{
            r--; p[r]=br[i];
        }
    }

    for(int i=1;i<=len;i++){
        ans+=(long long) (p[i])*(p[i]-1)/2+p[i];
    }

    for(int i=2;i<=len;i++){
        mult+=(long long) i*p[i];
        sum+=p[i];
    }

    for(int i=1;i<len;i++){
        ans+=p[i]*mult;

        mult-=sum+p[i+1];
        sum-=p[i+1];
    }

    cout<<ans<<"\n";
    
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 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 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 460 KB Output is correct
10 Correct 1 ms 460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 460 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 5 ms 880 KB Output is correct
5 Correct 10 ms 1628 KB Output is correct
6 Correct 17 ms 2128 KB Output is correct
7 Correct 12 ms 2140 KB Output is correct
8 Correct 11 ms 2216 KB Output is correct
9 Correct 14 ms 2212 KB Output is correct
10 Correct 12 ms 2140 KB Output is correct
11 Correct 12 ms 2136 KB Output is correct
12 Correct 17 ms 2132 KB Output is correct
13 Correct 11 ms 2056 KB Output is correct
14 Correct 14 ms 2140 KB Output is correct
15 Correct 11 ms 2100 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 460 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 5 ms 880 KB Output is correct
5 Correct 10 ms 1628 KB Output is correct
6 Correct 17 ms 2128 KB Output is correct
7 Correct 12 ms 2140 KB Output is correct
8 Correct 11 ms 2216 KB Output is correct
9 Correct 14 ms 2212 KB Output is correct
10 Correct 12 ms 2140 KB Output is correct
11 Correct 12 ms 2136 KB Output is correct
12 Correct 17 ms 2132 KB Output is correct
13 Correct 11 ms 2056 KB Output is correct
14 Correct 14 ms 2140 KB Output is correct
15 Correct 11 ms 2100 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 5 ms 1132 KB Output is correct
20 Correct 11 ms 1684 KB Output is correct
21 Correct 12 ms 2396 KB Output is correct
22 Correct 14 ms 2200 KB Output is correct
23 Correct 13 ms 2396 KB Output is correct
24 Correct 12 ms 2184 KB Output is correct
25 Correct 12 ms 2396 KB Output is correct
26 Correct 15 ms 2376 KB Output is correct
27 Correct 12 ms 2204 KB Output is correct
28 Correct 14 ms 2312 KB Output is correct
29 Correct 14 ms 2300 KB Output is correct
30 Correct 13 ms 2392 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 460 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 5 ms 880 KB Output is correct
5 Correct 10 ms 1628 KB Output is correct
6 Correct 17 ms 2128 KB Output is correct
7 Correct 12 ms 2140 KB Output is correct
8 Correct 11 ms 2216 KB Output is correct
9 Correct 14 ms 2212 KB Output is correct
10 Correct 12 ms 2140 KB Output is correct
11 Correct 12 ms 2136 KB Output is correct
12 Correct 17 ms 2132 KB Output is correct
13 Correct 11 ms 2056 KB Output is correct
14 Correct 14 ms 2140 KB Output is correct
15 Correct 11 ms 2100 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 5 ms 1132 KB Output is correct
20 Correct 11 ms 1684 KB Output is correct
21 Correct 12 ms 2396 KB Output is correct
22 Correct 14 ms 2200 KB Output is correct
23 Correct 13 ms 2396 KB Output is correct
24 Correct 12 ms 2184 KB Output is correct
25 Correct 12 ms 2396 KB Output is correct
26 Correct 15 ms 2376 KB Output is correct
27 Correct 12 ms 2204 KB Output is correct
28 Correct 14 ms 2312 KB Output is correct
29 Correct 14 ms 2300 KB Output is correct
30 Correct 13 ms 2392 KB Output is correct
31 Correct 0 ms 472 KB Output is correct
32 Correct 0 ms 352 KB Output is correct
33 Correct 0 ms 352 KB Output is correct
34 Correct 1 ms 352 KB Output is correct
35 Correct 1 ms 524 KB Output is correct
36 Correct 1 ms 356 KB Output is correct
37 Correct 3 ms 740 KB Output is correct
38 Correct 2 ms 860 KB Output is correct
39 Correct 4 ms 1116 KB Output is correct
40 Correct 9 ms 1884 KB Output is correct
41 Correct 15 ms 2652 KB Output is correct
42 Correct 17 ms 2652 KB Output is correct
43 Correct 15 ms 2652 KB Output is correct
44 Correct 17 ms 2780 KB Output is correct
45 Correct 18 ms 2648 KB Output is correct
46 Correct 13 ms 2652 KB Output is correct
47 Correct 13 ms 2652 KB Output is correct
48 Correct 14 ms 2556 KB Output is correct
49 Correct 16 ms 2656 KB Output is correct
50 Correct 14 ms 2652 KB Output is correct
51 Correct 14 ms 2640 KB Output is correct
52 Correct 15 ms 2652 KB Output is correct
53 Correct 17 ms 2652 KB Output is correct
54 Correct 21 ms 2792 KB Output is correct
55 Correct 19 ms 2752 KB Output is correct
56 Correct 17 ms 2568 KB Output is correct
57 Correct 13 ms 2652 KB Output is correct
58 Correct 17 ms 2668 KB Output is correct
59 Correct 18 ms 2652 KB Output is correct
60 Correct 14 ms 2652 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 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 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 460 KB Output is correct
10 Correct 1 ms 460 KB Output is correct
11 Correct 0 ms 460 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 5 ms 880 KB Output is correct
15 Correct 10 ms 1628 KB Output is correct
16 Correct 17 ms 2128 KB Output is correct
17 Correct 12 ms 2140 KB Output is correct
18 Correct 11 ms 2216 KB Output is correct
19 Correct 14 ms 2212 KB Output is correct
20 Correct 12 ms 2140 KB Output is correct
21 Correct 12 ms 2136 KB Output is correct
22 Correct 17 ms 2132 KB Output is correct
23 Correct 11 ms 2056 KB Output is correct
24 Correct 14 ms 2140 KB Output is correct
25 Correct 11 ms 2100 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 5 ms 1132 KB Output is correct
30 Correct 11 ms 1684 KB Output is correct
31 Correct 12 ms 2396 KB Output is correct
32 Correct 14 ms 2200 KB Output is correct
33 Correct 13 ms 2396 KB Output is correct
34 Correct 12 ms 2184 KB Output is correct
35 Correct 12 ms 2396 KB Output is correct
36 Correct 15 ms 2376 KB Output is correct
37 Correct 12 ms 2204 KB Output is correct
38 Correct 14 ms 2312 KB Output is correct
39 Correct 14 ms 2300 KB Output is correct
40 Correct 13 ms 2392 KB Output is correct
41 Correct 0 ms 472 KB Output is correct
42 Correct 0 ms 352 KB Output is correct
43 Correct 0 ms 352 KB Output is correct
44 Correct 1 ms 352 KB Output is correct
45 Correct 1 ms 524 KB Output is correct
46 Correct 1 ms 356 KB Output is correct
47 Correct 3 ms 740 KB Output is correct
48 Correct 2 ms 860 KB Output is correct
49 Correct 4 ms 1116 KB Output is correct
50 Correct 9 ms 1884 KB Output is correct
51 Correct 15 ms 2652 KB Output is correct
52 Correct 17 ms 2652 KB Output is correct
53 Correct 15 ms 2652 KB Output is correct
54 Correct 17 ms 2780 KB Output is correct
55 Correct 18 ms 2648 KB Output is correct
56 Correct 13 ms 2652 KB Output is correct
57 Correct 13 ms 2652 KB Output is correct
58 Correct 14 ms 2556 KB Output is correct
59 Correct 16 ms 2656 KB Output is correct
60 Correct 14 ms 2652 KB Output is correct
61 Correct 14 ms 2640 KB Output is correct
62 Correct 15 ms 2652 KB Output is correct
63 Correct 17 ms 2652 KB Output is correct
64 Correct 21 ms 2792 KB Output is correct
65 Correct 19 ms 2752 KB Output is correct
66 Correct 17 ms 2568 KB Output is correct
67 Correct 13 ms 2652 KB Output is correct
68 Correct 17 ms 2668 KB Output is correct
69 Correct 18 ms 2652 KB Output is correct
70 Correct 14 ms 2652 KB Output is correct
71 Correct 3 ms 728 KB Output is correct
72 Correct 4 ms 732 KB Output is correct
73 Correct 4 ms 860 KB Output is correct
74 Correct 3 ms 860 KB Output is correct
75 Correct 3 ms 896 KB Output is correct
76 Correct 6 ms 1128 KB Output is correct
77 Correct 5 ms 1372 KB Output is correct
78 Correct 7 ms 1172 KB Output is correct
79 Correct 6 ms 1132 KB Output is correct
80 Correct 6 ms 1180 KB Output is correct
81 Correct 14 ms 2088 KB Output is correct
82 Correct 12 ms 2244 KB Output is correct
83 Correct 11 ms 2140 KB Output is correct
84 Correct 13 ms 2176 KB Output is correct
85 Correct 12 ms 2176 KB Output is correct
86 Correct 17 ms 2260 KB Output is correct
87 Correct 12 ms 2300 KB Output is correct
88 Correct 13 ms 2300 KB Output is correct
89 Correct 17 ms 2260 KB Output is correct
90 Correct 13 ms 2468 KB Output is correct
91 Correct 21 ms 4124 KB Output is correct
92 Correct 23 ms 4068 KB Output is correct
93 Correct 21 ms 3992 KB Output is correct
94 Correct 22 ms 4016 KB Output is correct
95 Correct 22 ms 3924 KB Output is correct
96 Correct 25 ms 5072 KB Output is correct
97 Correct 28 ms 4976 KB Output is correct
98 Correct 26 ms 4932 KB Output is correct
99 Correct 26 ms 4888 KB Output is correct
100 Correct 32 ms 5020 KB Output is correct
101 Correct 30 ms 4948 KB Output is correct
102 Correct 28 ms 4948 KB Output is correct
103 Correct 26 ms 5088 KB Output is correct
104 Correct 27 ms 5004 KB Output is correct
105 Correct 25 ms 4956 KB Output is correct
106 Correct 26 ms 5468 KB Output is correct
107 Correct 44 ms 5468 KB Output is correct
108 Correct 24 ms 5464 KB Output is correct
109 Correct 25 ms 5464 KB Output is correct
110 Correct 29 ms 5436 KB Output is correct
111 Correct 24 ms 5468 KB Output is correct
112 Correct 24 ms 5464 KB Output is correct
113 Correct 28 ms 5460 KB Output is correct
114 Correct 27 ms 5332 KB Output is correct
115 Correct 26 ms 5260 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 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 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 460 KB Output is correct
10 Correct 1 ms 460 KB Output is correct
11 Correct 0 ms 460 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 5 ms 880 KB Output is correct
15 Correct 10 ms 1628 KB Output is correct
16 Correct 17 ms 2128 KB Output is correct
17 Correct 12 ms 2140 KB Output is correct
18 Correct 11 ms 2216 KB Output is correct
19 Correct 14 ms 2212 KB Output is correct
20 Correct 12 ms 2140 KB Output is correct
21 Correct 12 ms 2136 KB Output is correct
22 Correct 17 ms 2132 KB Output is correct
23 Correct 11 ms 2056 KB Output is correct
24 Correct 14 ms 2140 KB Output is correct
25 Correct 11 ms 2100 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 5 ms 1132 KB Output is correct
30 Correct 11 ms 1684 KB Output is correct
31 Correct 12 ms 2396 KB Output is correct
32 Correct 14 ms 2200 KB Output is correct
33 Correct 13 ms 2396 KB Output is correct
34 Correct 12 ms 2184 KB Output is correct
35 Correct 12 ms 2396 KB Output is correct
36 Correct 15 ms 2376 KB Output is correct
37 Correct 12 ms 2204 KB Output is correct
38 Correct 14 ms 2312 KB Output is correct
39 Correct 14 ms 2300 KB Output is correct
40 Correct 13 ms 2392 KB Output is correct
41 Correct 0 ms 472 KB Output is correct
42 Correct 0 ms 352 KB Output is correct
43 Correct 0 ms 352 KB Output is correct
44 Correct 1 ms 352 KB Output is correct
45 Correct 1 ms 524 KB Output is correct
46 Correct 1 ms 356 KB Output is correct
47 Correct 3 ms 740 KB Output is correct
48 Correct 2 ms 860 KB Output is correct
49 Correct 4 ms 1116 KB Output is correct
50 Correct 9 ms 1884 KB Output is correct
51 Correct 15 ms 2652 KB Output is correct
52 Correct 17 ms 2652 KB Output is correct
53 Correct 15 ms 2652 KB Output is correct
54 Correct 17 ms 2780 KB Output is correct
55 Correct 18 ms 2648 KB Output is correct
56 Correct 13 ms 2652 KB Output is correct
57 Correct 13 ms 2652 KB Output is correct
58 Correct 14 ms 2556 KB Output is correct
59 Correct 16 ms 2656 KB Output is correct
60 Correct 14 ms 2652 KB Output is correct
61 Correct 14 ms 2640 KB Output is correct
62 Correct 15 ms 2652 KB Output is correct
63 Correct 17 ms 2652 KB Output is correct
64 Correct 21 ms 2792 KB Output is correct
65 Correct 19 ms 2752 KB Output is correct
66 Correct 17 ms 2568 KB Output is correct
67 Correct 13 ms 2652 KB Output is correct
68 Correct 17 ms 2668 KB Output is correct
69 Correct 18 ms 2652 KB Output is correct
70 Correct 14 ms 2652 KB Output is correct
71 Correct 3 ms 728 KB Output is correct
72 Correct 4 ms 732 KB Output is correct
73 Correct 4 ms 860 KB Output is correct
74 Correct 3 ms 860 KB Output is correct
75 Correct 3 ms 896 KB Output is correct
76 Correct 6 ms 1128 KB Output is correct
77 Correct 5 ms 1372 KB Output is correct
78 Correct 7 ms 1172 KB Output is correct
79 Correct 6 ms 1132 KB Output is correct
80 Correct 6 ms 1180 KB Output is correct
81 Correct 14 ms 2088 KB Output is correct
82 Correct 12 ms 2244 KB Output is correct
83 Correct 11 ms 2140 KB Output is correct
84 Correct 13 ms 2176 KB Output is correct
85 Correct 12 ms 2176 KB Output is correct
86 Correct 17 ms 2260 KB Output is correct
87 Correct 12 ms 2300 KB Output is correct
88 Correct 13 ms 2300 KB Output is correct
89 Correct 17 ms 2260 KB Output is correct
90 Correct 13 ms 2468 KB Output is correct
91 Correct 21 ms 4124 KB Output is correct
92 Correct 23 ms 4068 KB Output is correct
93 Correct 21 ms 3992 KB Output is correct
94 Correct 22 ms 4016 KB Output is correct
95 Correct 22 ms 3924 KB Output is correct
96 Correct 25 ms 5072 KB Output is correct
97 Correct 28 ms 4976 KB Output is correct
98 Correct 26 ms 4932 KB Output is correct
99 Correct 26 ms 4888 KB Output is correct
100 Correct 32 ms 5020 KB Output is correct
101 Correct 30 ms 4948 KB Output is correct
102 Correct 28 ms 4948 KB Output is correct
103 Correct 26 ms 5088 KB Output is correct
104 Correct 27 ms 5004 KB Output is correct
105 Correct 25 ms 4956 KB Output is correct
106 Correct 26 ms 5468 KB Output is correct
107 Correct 44 ms 5468 KB Output is correct
108 Correct 24 ms 5464 KB Output is correct
109 Correct 25 ms 5464 KB Output is correct
110 Correct 29 ms 5436 KB Output is correct
111 Correct 24 ms 5468 KB Output is correct
112 Correct 24 ms 5464 KB Output is correct
113 Correct 28 ms 5460 KB Output is correct
114 Correct 27 ms 5332 KB Output is correct
115 Correct 26 ms 5260 KB Output is correct
116 Incorrect 1 ms 600 KB Output isn't correct
117 Halted 0 ms 0 KB -