답안 #549564

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
549564 2022-04-16T04:01:40 Z minhcool Diversity (CEOI21_diversity) C++17
64 / 100
90 ms 8968 KB
#include<bits/stdc++.h>
using namespace std;

#define int long long
#define fi first
#define se second
#define pb push_back

typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<ii, ii> iiii;

const int N = 4e5 + 5;

const int oo = 1e18 + 7, mod = 1e9 + 7;

int n, q, a[N];

ii cnt[N];

int cntt[N];

void process(){
    cin >> n >> q;
    for(int i = 1; i <= n; i++){
        cin >> a[i];
        cnt[a[i]].fi++;
    }
    for(int i = 1; i <= 300000; i++){
        cntt[cnt[i].fi]++;
        cnt[i].se = i;
    }
    sort(cnt + 1, cnt + 300000 + 1, greater<ii>());
    deque<int> dq;
    vector<ii> vc1, vc2;
    int total = 0;
    for(int i = 1; i <= 300000; i++){
        int temp1 = (cntt[i] + 1) / 2, temp2 = cntt[i] / 2;
        if(!(total & 1)){
            if(temp1) vc1.pb({i, temp1});
            if(temp2) vc2.pb({i, temp2});
        }
        else{
            if(temp2) vc1.pb({i, temp2});
            if(temp1) vc2.pb({i, temp1});
        }
        total += cntt[i];
    }
    for(int i = vc2.size() - 1; i >= 0; i--) vc1.pb(vc2[i]);
    int tol = 0, tol2 = 0, toll = 1;
    /*
    tol: total before, tol2: answer, toll: answer for i
    */
    for(auto it : vc1){
        // 1, 3, 6, 10
        // 1, 2, 5, 6, 11, 12, ...
        // 1, 2, 3, 7, 8, 9, 16, 17, 18, 28, 29, 30, ... 
        // 1, 1, 1, 7, 7, 7, 16, 16, 16, 28, 28, 28, ...
        // 
        /*
        it.se * (it.se + 1) / 2
        tol + 1, tol + 2 * it.fi, tol + 5 * it.fi, ..., tol + 9 * it.fi
        1 + 3 + 6 + 10 + 15 - 5
        1*2/2 + 2*3/2 + 3*4/2 + 4*5/2 + 5*6/2 - 5
        (1*2 + 2*3 + 3*4 + 4*5 + 5*6) / 2 - 5
        ((1*1 + 2*2 + 3*3 + 4*4 + 5*5) + (1+2+3+4+5)) / 2 - 5
        
        */
        int temp = ((it.se * (it.se + 1) * (2 * it.se + 1)) / 6 + (it.se * (it.se + 1)) / 2) / 2 - it.se;
        //cout << temp << "\n";
        temp = temp * it.fi * it.fi + toll * it.fi * it.se;
        //cout << temp << "\n";
        temp += it.se * (it.fi * (it.fi - 1) / 2);
        temp += tol * ((it.se * (it.se - 1)) / 2) * it.fi;
        //cout << temp << "\n";
        toll += ((it.se * (it.se + 1)) / 2) * it.fi + tol * (it.se - 1);
        tol += it.fi * it.se;
        //cout << toll << "\n";
        toll += tol;
        tol2 += temp;
        //cout << it.fi << " " << it.se << "\n";
        //cout << tol << " " << toll << " " << tol2 << "\n";
    }
    cout << tol2 << "\n";
    // 0, 0, 4, 5, 10, 11
    // 1, 2, 5, 6, 11, 12, 19, 20, 29, 30, 41
    // 0, 0, 4, 4, 10, 10
    /*
    tol = toll = tol2 = 0;
    for(int i = 299999; i >= 1; i -= 2){
        tol2 += (cnt[i].fi * (cnt[i].fi + 1)) / 2;
        tol2 += (cnt[i].fi * tol);
        tol += cnt[i].fi;
        toll += cnt[i].fi;
        tol += toll;
    }
    for(int i = 2; i <= 300000; i += 2){
        tol2 += (cnt[i].fi * (cnt[i].fi + 1)) / 2;
        tol2 += (cnt[i].fi * tol);
        tol += cnt[i].fi;
        toll += cnt[i].fi;
        tol += toll;
    }*/
    /*
    for(int i = 1; i <= 300000; i++){
        if(i & 1) for(int j = 1; j <= cnt[i].fi; j++) dq.push_front(cnt[i].se);
        else for(int j = 1; j <= cnt[i].fi; j++) dq.push_back(cnt[i].se);
    }
    int cnt = 0,  lst = -1;
    tol = 0, tol2 = 0;
    //cout << dq.size() << "\n";
    while(dq.size()){
        int u = dq.front();
        //cout << u << "\n";
        dq.pop_front();
        cnt++;
        if(lst != u) tol += cnt;
        else tol++;
        cout << tol << " ";
        tol2 += tol;
        lst = u;
    }
    cout << tol2 << "\n";*/
}

signed main(){
    ios_base::sync_with_stdio(0);
    process();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 4936 KB Output is correct
2 Correct 38 ms 4948 KB Output is correct
3 Correct 36 ms 4948 KB Output is correct
4 Correct 36 ms 4948 KB Output is correct
5 Correct 36 ms 4948 KB Output is correct
6 Correct 35 ms 5016 KB Output is correct
7 Correct 36 ms 5012 KB Output is correct
8 Correct 41 ms 5148 KB Output is correct
9 Correct 47 ms 4948 KB Output is correct
10 Correct 38 ms 4948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 36 ms 4948 KB Output is correct
2 Correct 38 ms 5032 KB Output is correct
3 Correct 40 ms 5204 KB Output is correct
4 Correct 45 ms 6028 KB Output is correct
5 Correct 50 ms 6984 KB Output is correct
6 Correct 62 ms 8092 KB Output is correct
7 Correct 53 ms 8024 KB Output is correct
8 Correct 50 ms 8024 KB Output is correct
9 Correct 53 ms 8124 KB Output is correct
10 Correct 58 ms 8016 KB Output is correct
11 Correct 60 ms 8060 KB Output is correct
12 Correct 65 ms 8136 KB Output is correct
13 Correct 52 ms 8020 KB Output is correct
14 Correct 52 ms 8068 KB Output is correct
15 Correct 57 ms 8012 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 36 ms 4948 KB Output is correct
2 Correct 38 ms 5032 KB Output is correct
3 Correct 40 ms 5204 KB Output is correct
4 Correct 45 ms 6028 KB Output is correct
5 Correct 50 ms 6984 KB Output is correct
6 Correct 62 ms 8092 KB Output is correct
7 Correct 53 ms 8024 KB Output is correct
8 Correct 50 ms 8024 KB Output is correct
9 Correct 53 ms 8124 KB Output is correct
10 Correct 58 ms 8016 KB Output is correct
11 Correct 60 ms 8060 KB Output is correct
12 Correct 65 ms 8136 KB Output is correct
13 Correct 52 ms 8020 KB Output is correct
14 Correct 52 ms 8068 KB Output is correct
15 Correct 57 ms 8012 KB Output is correct
16 Correct 39 ms 5016 KB Output is correct
17 Correct 37 ms 4948 KB Output is correct
18 Correct 40 ms 5076 KB Output is correct
19 Correct 49 ms 6224 KB Output is correct
20 Correct 49 ms 7176 KB Output is correct
21 Correct 54 ms 8148 KB Output is correct
22 Correct 59 ms 8208 KB Output is correct
23 Correct 76 ms 8232 KB Output is correct
24 Correct 57 ms 8212 KB Output is correct
25 Correct 58 ms 8156 KB Output is correct
26 Correct 56 ms 8204 KB Output is correct
27 Correct 71 ms 8224 KB Output is correct
28 Correct 58 ms 8180 KB Output is correct
29 Correct 56 ms 8200 KB Output is correct
30 Correct 58 ms 8236 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 36 ms 4948 KB Output is correct
2 Correct 38 ms 5032 KB Output is correct
3 Correct 40 ms 5204 KB Output is correct
4 Correct 45 ms 6028 KB Output is correct
5 Correct 50 ms 6984 KB Output is correct
6 Correct 62 ms 8092 KB Output is correct
7 Correct 53 ms 8024 KB Output is correct
8 Correct 50 ms 8024 KB Output is correct
9 Correct 53 ms 8124 KB Output is correct
10 Correct 58 ms 8016 KB Output is correct
11 Correct 60 ms 8060 KB Output is correct
12 Correct 65 ms 8136 KB Output is correct
13 Correct 52 ms 8020 KB Output is correct
14 Correct 52 ms 8068 KB Output is correct
15 Correct 57 ms 8012 KB Output is correct
16 Correct 39 ms 5016 KB Output is correct
17 Correct 37 ms 4948 KB Output is correct
18 Correct 40 ms 5076 KB Output is correct
19 Correct 49 ms 6224 KB Output is correct
20 Correct 49 ms 7176 KB Output is correct
21 Correct 54 ms 8148 KB Output is correct
22 Correct 59 ms 8208 KB Output is correct
23 Correct 76 ms 8232 KB Output is correct
24 Correct 57 ms 8212 KB Output is correct
25 Correct 58 ms 8156 KB Output is correct
26 Correct 56 ms 8204 KB Output is correct
27 Correct 71 ms 8224 KB Output is correct
28 Correct 58 ms 8180 KB Output is correct
29 Correct 56 ms 8200 KB Output is correct
30 Correct 58 ms 8236 KB Output is correct
31 Correct 38 ms 4936 KB Output is correct
32 Correct 35 ms 4932 KB Output is correct
33 Correct 38 ms 5032 KB Output is correct
34 Correct 38 ms 5076 KB Output is correct
35 Correct 41 ms 5132 KB Output is correct
36 Correct 41 ms 5076 KB Output is correct
37 Correct 41 ms 5608 KB Output is correct
38 Correct 40 ms 5612 KB Output is correct
39 Correct 44 ms 6184 KB Output is correct
40 Correct 51 ms 7376 KB Output is correct
41 Correct 61 ms 8500 KB Output is correct
42 Correct 62 ms 8628 KB Output is correct
43 Correct 73 ms 8512 KB Output is correct
44 Correct 58 ms 8524 KB Output is correct
45 Correct 67 ms 8512 KB Output is correct
46 Correct 63 ms 8468 KB Output is correct
47 Correct 74 ms 8524 KB Output is correct
48 Correct 63 ms 8516 KB Output is correct
49 Correct 61 ms 8508 KB Output is correct
50 Correct 63 ms 8504 KB Output is correct
51 Correct 57 ms 8520 KB Output is correct
52 Correct 71 ms 8504 KB Output is correct
53 Correct 58 ms 8512 KB Output is correct
54 Correct 59 ms 8520 KB Output is correct
55 Correct 57 ms 8516 KB Output is correct
56 Correct 74 ms 8516 KB Output is correct
57 Correct 66 ms 8504 KB Output is correct
58 Correct 62 ms 8508 KB Output is correct
59 Correct 56 ms 8516 KB Output is correct
60 Correct 61 ms 8508 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 4936 KB Output is correct
2 Correct 38 ms 4948 KB Output is correct
3 Correct 36 ms 4948 KB Output is correct
4 Correct 36 ms 4948 KB Output is correct
5 Correct 36 ms 4948 KB Output is correct
6 Correct 35 ms 5016 KB Output is correct
7 Correct 36 ms 5012 KB Output is correct
8 Correct 41 ms 5148 KB Output is correct
9 Correct 47 ms 4948 KB Output is correct
10 Correct 38 ms 4948 KB Output is correct
11 Correct 36 ms 4948 KB Output is correct
12 Correct 38 ms 5032 KB Output is correct
13 Correct 40 ms 5204 KB Output is correct
14 Correct 45 ms 6028 KB Output is correct
15 Correct 50 ms 6984 KB Output is correct
16 Correct 62 ms 8092 KB Output is correct
17 Correct 53 ms 8024 KB Output is correct
18 Correct 50 ms 8024 KB Output is correct
19 Correct 53 ms 8124 KB Output is correct
20 Correct 58 ms 8016 KB Output is correct
21 Correct 60 ms 8060 KB Output is correct
22 Correct 65 ms 8136 KB Output is correct
23 Correct 52 ms 8020 KB Output is correct
24 Correct 52 ms 8068 KB Output is correct
25 Correct 57 ms 8012 KB Output is correct
26 Correct 39 ms 5016 KB Output is correct
27 Correct 37 ms 4948 KB Output is correct
28 Correct 40 ms 5076 KB Output is correct
29 Correct 49 ms 6224 KB Output is correct
30 Correct 49 ms 7176 KB Output is correct
31 Correct 54 ms 8148 KB Output is correct
32 Correct 59 ms 8208 KB Output is correct
33 Correct 76 ms 8232 KB Output is correct
34 Correct 57 ms 8212 KB Output is correct
35 Correct 58 ms 8156 KB Output is correct
36 Correct 56 ms 8204 KB Output is correct
37 Correct 71 ms 8224 KB Output is correct
38 Correct 58 ms 8180 KB Output is correct
39 Correct 56 ms 8200 KB Output is correct
40 Correct 58 ms 8236 KB Output is correct
41 Correct 38 ms 4936 KB Output is correct
42 Correct 35 ms 4932 KB Output is correct
43 Correct 38 ms 5032 KB Output is correct
44 Correct 38 ms 5076 KB Output is correct
45 Correct 41 ms 5132 KB Output is correct
46 Correct 41 ms 5076 KB Output is correct
47 Correct 41 ms 5608 KB Output is correct
48 Correct 40 ms 5612 KB Output is correct
49 Correct 44 ms 6184 KB Output is correct
50 Correct 51 ms 7376 KB Output is correct
51 Correct 61 ms 8500 KB Output is correct
52 Correct 62 ms 8628 KB Output is correct
53 Correct 73 ms 8512 KB Output is correct
54 Correct 58 ms 8524 KB Output is correct
55 Correct 67 ms 8512 KB Output is correct
56 Correct 63 ms 8468 KB Output is correct
57 Correct 74 ms 8524 KB Output is correct
58 Correct 63 ms 8516 KB Output is correct
59 Correct 61 ms 8508 KB Output is correct
60 Correct 63 ms 8504 KB Output is correct
61 Correct 57 ms 8520 KB Output is correct
62 Correct 71 ms 8504 KB Output is correct
63 Correct 58 ms 8512 KB Output is correct
64 Correct 59 ms 8520 KB Output is correct
65 Correct 57 ms 8516 KB Output is correct
66 Correct 74 ms 8516 KB Output is correct
67 Correct 66 ms 8504 KB Output is correct
68 Correct 62 ms 8508 KB Output is correct
69 Correct 56 ms 8516 KB Output is correct
70 Correct 61 ms 8508 KB Output is correct
71 Correct 48 ms 5588 KB Output is correct
72 Correct 50 ms 5588 KB Output is correct
73 Correct 42 ms 5644 KB Output is correct
74 Correct 40 ms 5640 KB Output is correct
75 Correct 40 ms 5588 KB Output is correct
76 Correct 46 ms 6268 KB Output is correct
77 Correct 42 ms 6268 KB Output is correct
78 Correct 47 ms 6228 KB Output is correct
79 Correct 62 ms 6276 KB Output is correct
80 Correct 45 ms 6268 KB Output is correct
81 Correct 51 ms 7484 KB Output is correct
82 Correct 52 ms 7524 KB Output is correct
83 Correct 52 ms 7448 KB Output is correct
84 Correct 58 ms 7520 KB Output is correct
85 Correct 55 ms 7528 KB Output is correct
86 Correct 51 ms 7632 KB Output is correct
87 Correct 55 ms 7640 KB Output is correct
88 Correct 51 ms 7604 KB Output is correct
89 Correct 52 ms 7632 KB Output is correct
90 Correct 56 ms 7632 KB Output is correct
91 Correct 61 ms 8900 KB Output is correct
92 Correct 64 ms 8968 KB Output is correct
93 Correct 73 ms 8876 KB Output is correct
94 Correct 84 ms 8900 KB Output is correct
95 Correct 77 ms 8888 KB Output is correct
96 Correct 57 ms 8808 KB Output is correct
97 Correct 54 ms 8908 KB Output is correct
98 Correct 54 ms 8896 KB Output is correct
99 Correct 56 ms 8888 KB Output is correct
100 Correct 70 ms 8952 KB Output is correct
101 Correct 88 ms 8904 KB Output is correct
102 Correct 52 ms 8852 KB Output is correct
103 Correct 61 ms 8856 KB Output is correct
104 Correct 69 ms 8916 KB Output is correct
105 Correct 65 ms 8908 KB Output is correct
106 Correct 62 ms 8920 KB Output is correct
107 Correct 52 ms 8868 KB Output is correct
108 Correct 53 ms 8900 KB Output is correct
109 Correct 52 ms 8904 KB Output is correct
110 Correct 90 ms 8876 KB Output is correct
111 Correct 82 ms 8796 KB Output is correct
112 Correct 50 ms 8896 KB Output is correct
113 Correct 53 ms 8888 KB Output is correct
114 Correct 58 ms 8904 KB Output is correct
115 Correct 63 ms 8824 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 4936 KB Output is correct
2 Correct 38 ms 4948 KB Output is correct
3 Correct 36 ms 4948 KB Output is correct
4 Correct 36 ms 4948 KB Output is correct
5 Correct 36 ms 4948 KB Output is correct
6 Correct 35 ms 5016 KB Output is correct
7 Correct 36 ms 5012 KB Output is correct
8 Correct 41 ms 5148 KB Output is correct
9 Correct 47 ms 4948 KB Output is correct
10 Correct 38 ms 4948 KB Output is correct
11 Correct 36 ms 4948 KB Output is correct
12 Correct 38 ms 5032 KB Output is correct
13 Correct 40 ms 5204 KB Output is correct
14 Correct 45 ms 6028 KB Output is correct
15 Correct 50 ms 6984 KB Output is correct
16 Correct 62 ms 8092 KB Output is correct
17 Correct 53 ms 8024 KB Output is correct
18 Correct 50 ms 8024 KB Output is correct
19 Correct 53 ms 8124 KB Output is correct
20 Correct 58 ms 8016 KB Output is correct
21 Correct 60 ms 8060 KB Output is correct
22 Correct 65 ms 8136 KB Output is correct
23 Correct 52 ms 8020 KB Output is correct
24 Correct 52 ms 8068 KB Output is correct
25 Correct 57 ms 8012 KB Output is correct
26 Correct 39 ms 5016 KB Output is correct
27 Correct 37 ms 4948 KB Output is correct
28 Correct 40 ms 5076 KB Output is correct
29 Correct 49 ms 6224 KB Output is correct
30 Correct 49 ms 7176 KB Output is correct
31 Correct 54 ms 8148 KB Output is correct
32 Correct 59 ms 8208 KB Output is correct
33 Correct 76 ms 8232 KB Output is correct
34 Correct 57 ms 8212 KB Output is correct
35 Correct 58 ms 8156 KB Output is correct
36 Correct 56 ms 8204 KB Output is correct
37 Correct 71 ms 8224 KB Output is correct
38 Correct 58 ms 8180 KB Output is correct
39 Correct 56 ms 8200 KB Output is correct
40 Correct 58 ms 8236 KB Output is correct
41 Correct 38 ms 4936 KB Output is correct
42 Correct 35 ms 4932 KB Output is correct
43 Correct 38 ms 5032 KB Output is correct
44 Correct 38 ms 5076 KB Output is correct
45 Correct 41 ms 5132 KB Output is correct
46 Correct 41 ms 5076 KB Output is correct
47 Correct 41 ms 5608 KB Output is correct
48 Correct 40 ms 5612 KB Output is correct
49 Correct 44 ms 6184 KB Output is correct
50 Correct 51 ms 7376 KB Output is correct
51 Correct 61 ms 8500 KB Output is correct
52 Correct 62 ms 8628 KB Output is correct
53 Correct 73 ms 8512 KB Output is correct
54 Correct 58 ms 8524 KB Output is correct
55 Correct 67 ms 8512 KB Output is correct
56 Correct 63 ms 8468 KB Output is correct
57 Correct 74 ms 8524 KB Output is correct
58 Correct 63 ms 8516 KB Output is correct
59 Correct 61 ms 8508 KB Output is correct
60 Correct 63 ms 8504 KB Output is correct
61 Correct 57 ms 8520 KB Output is correct
62 Correct 71 ms 8504 KB Output is correct
63 Correct 58 ms 8512 KB Output is correct
64 Correct 59 ms 8520 KB Output is correct
65 Correct 57 ms 8516 KB Output is correct
66 Correct 74 ms 8516 KB Output is correct
67 Correct 66 ms 8504 KB Output is correct
68 Correct 62 ms 8508 KB Output is correct
69 Correct 56 ms 8516 KB Output is correct
70 Correct 61 ms 8508 KB Output is correct
71 Correct 48 ms 5588 KB Output is correct
72 Correct 50 ms 5588 KB Output is correct
73 Correct 42 ms 5644 KB Output is correct
74 Correct 40 ms 5640 KB Output is correct
75 Correct 40 ms 5588 KB Output is correct
76 Correct 46 ms 6268 KB Output is correct
77 Correct 42 ms 6268 KB Output is correct
78 Correct 47 ms 6228 KB Output is correct
79 Correct 62 ms 6276 KB Output is correct
80 Correct 45 ms 6268 KB Output is correct
81 Correct 51 ms 7484 KB Output is correct
82 Correct 52 ms 7524 KB Output is correct
83 Correct 52 ms 7448 KB Output is correct
84 Correct 58 ms 7520 KB Output is correct
85 Correct 55 ms 7528 KB Output is correct
86 Correct 51 ms 7632 KB Output is correct
87 Correct 55 ms 7640 KB Output is correct
88 Correct 51 ms 7604 KB Output is correct
89 Correct 52 ms 7632 KB Output is correct
90 Correct 56 ms 7632 KB Output is correct
91 Correct 61 ms 8900 KB Output is correct
92 Correct 64 ms 8968 KB Output is correct
93 Correct 73 ms 8876 KB Output is correct
94 Correct 84 ms 8900 KB Output is correct
95 Correct 77 ms 8888 KB Output is correct
96 Correct 57 ms 8808 KB Output is correct
97 Correct 54 ms 8908 KB Output is correct
98 Correct 54 ms 8896 KB Output is correct
99 Correct 56 ms 8888 KB Output is correct
100 Correct 70 ms 8952 KB Output is correct
101 Correct 88 ms 8904 KB Output is correct
102 Correct 52 ms 8852 KB Output is correct
103 Correct 61 ms 8856 KB Output is correct
104 Correct 69 ms 8916 KB Output is correct
105 Correct 65 ms 8908 KB Output is correct
106 Correct 62 ms 8920 KB Output is correct
107 Correct 52 ms 8868 KB Output is correct
108 Correct 53 ms 8900 KB Output is correct
109 Correct 52 ms 8904 KB Output is correct
110 Correct 90 ms 8876 KB Output is correct
111 Correct 82 ms 8796 KB Output is correct
112 Correct 50 ms 8896 KB Output is correct
113 Correct 53 ms 8888 KB Output is correct
114 Correct 58 ms 8904 KB Output is correct
115 Correct 63 ms 8824 KB Output is correct
116 Incorrect 43 ms 5208 KB Output isn't correct
117 Halted 0 ms 0 KB -