Submission #967559

# Submission time Handle Problem Language Result Execution time Memory
967559 2024-04-22T12:38:13 Z anton Diversity (CEOI21_diversity) C++17
64 / 100
225 ms 26456 KB
#include<bits/stdc++.h>

using namespace std;
#define int long long
#define pii pair<int, int>

struct seq{
    int s=0;
    int sc= 0;

    void insert(int v){
        s+= v;
        sc+=s;
    }
};
int arithmetic(int v){
    return v*(v+1)/2;
}
signed main(){
    cin.tie(NULL);
    ios_base::sync_with_stdio(false);
    int n, q;
    cin>>n>>q;
    vector<int> v(n);
    map<int, int> oc;
    for(int i = 0; i<n; i++){
        cin>>v[i];
        oc[v[i]] ++;
    }

    deque<int> dq;
    vector<pii> groups;
    for(auto e: oc){
        groups.push_back(e);
    }
    auto cmp =[&](pii& a, pii& b){
        return a.second>b.second;
    };
    sort(groups.begin(), groups.end(), cmp);


    int res= 0;
    for(int i = 0; i<groups.size(); i++){
        if(i%2 == 0){
            dq.push_back(groups[i].second);
        }
        else{
            dq.push_front(groups[i].second);
        }
        res += arithmetic(groups[i].second);
    }


    seq s;
    s.insert(dq.back());

    for(int i = dq.size()-2; i>=0; i--){
        res+= (s.s+s.sc)*dq[i];
        s.insert(dq[i]);
    }
    for(int i = 0; i<q; i++){
        int a, b;
        cin>>a>>b;
        cout<<res<<endl;
    }
}

Compilation message

diversity.cpp: In function 'int main()':
diversity.cpp:43:21: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |     for(int i = 0; i<groups.size(); i++){
      |                    ~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 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 6 ms 1112 KB Output is correct
5 Correct 10 ms 1884 KB Output is correct
6 Correct 16 ms 2648 KB Output is correct
7 Correct 14 ms 2652 KB Output is correct
8 Correct 16 ms 2816 KB Output is correct
9 Correct 15 ms 2652 KB Output is correct
10 Correct 17 ms 2648 KB Output is correct
11 Correct 15 ms 2652 KB Output is correct
12 Correct 16 ms 2812 KB Output is correct
13 Correct 16 ms 2648 KB Output is correct
14 Correct 19 ms 2652 KB Output is correct
15 Correct 15 ms 2652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 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 6 ms 1112 KB Output is correct
5 Correct 10 ms 1884 KB Output is correct
6 Correct 16 ms 2648 KB Output is correct
7 Correct 14 ms 2652 KB Output is correct
8 Correct 16 ms 2816 KB Output is correct
9 Correct 15 ms 2652 KB Output is correct
10 Correct 17 ms 2648 KB Output is correct
11 Correct 15 ms 2652 KB Output is correct
12 Correct 16 ms 2812 KB Output is correct
13 Correct 16 ms 2648 KB Output is correct
14 Correct 19 ms 2652 KB Output is correct
15 Correct 15 ms 2652 KB Output is correct
16 Correct 1 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 6 ms 1116 KB Output is correct
20 Correct 12 ms 1884 KB Output is correct
21 Correct 18 ms 2652 KB Output is correct
22 Correct 17 ms 2904 KB Output is correct
23 Correct 20 ms 2648 KB Output is correct
24 Correct 23 ms 2812 KB Output is correct
25 Correct 18 ms 2660 KB Output is correct
26 Correct 19 ms 2652 KB Output is correct
27 Correct 18 ms 2648 KB Output is correct
28 Correct 17 ms 2652 KB Output is correct
29 Correct 18 ms 2652 KB Output is correct
30 Correct 18 ms 2652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 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 6 ms 1112 KB Output is correct
5 Correct 10 ms 1884 KB Output is correct
6 Correct 16 ms 2648 KB Output is correct
7 Correct 14 ms 2652 KB Output is correct
8 Correct 16 ms 2816 KB Output is correct
9 Correct 15 ms 2652 KB Output is correct
10 Correct 17 ms 2648 KB Output is correct
11 Correct 15 ms 2652 KB Output is correct
12 Correct 16 ms 2812 KB Output is correct
13 Correct 16 ms 2648 KB Output is correct
14 Correct 19 ms 2652 KB Output is correct
15 Correct 15 ms 2652 KB Output is correct
16 Correct 1 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 6 ms 1116 KB Output is correct
20 Correct 12 ms 1884 KB Output is correct
21 Correct 18 ms 2652 KB Output is correct
22 Correct 17 ms 2904 KB Output is correct
23 Correct 20 ms 2648 KB Output is correct
24 Correct 23 ms 2812 KB Output is correct
25 Correct 18 ms 2660 KB Output is correct
26 Correct 19 ms 2652 KB Output is correct
27 Correct 18 ms 2648 KB Output is correct
28 Correct 17 ms 2652 KB Output is correct
29 Correct 18 ms 2652 KB Output is correct
30 Correct 18 ms 2652 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 1 ms 360 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 2 ms 604 KB Output is correct
37 Correct 5 ms 860 KB Output is correct
38 Correct 5 ms 860 KB Output is correct
39 Correct 10 ms 1116 KB Output is correct
40 Correct 19 ms 2104 KB Output is correct
41 Correct 30 ms 2908 KB Output is correct
42 Correct 38 ms 2648 KB Output is correct
43 Correct 28 ms 2908 KB Output is correct
44 Correct 28 ms 3124 KB Output is correct
45 Correct 29 ms 2648 KB Output is correct
46 Correct 28 ms 2648 KB Output is correct
47 Correct 28 ms 2876 KB Output is correct
48 Correct 29 ms 2652 KB Output is correct
49 Correct 29 ms 2652 KB Output is correct
50 Correct 29 ms 2908 KB Output is correct
51 Correct 29 ms 2908 KB Output is correct
52 Correct 28 ms 2648 KB Output is correct
53 Correct 28 ms 2884 KB Output is correct
54 Correct 29 ms 2880 KB Output is correct
55 Correct 28 ms 2908 KB Output is correct
56 Correct 29 ms 2652 KB Output is correct
57 Correct 28 ms 2872 KB Output is correct
58 Correct 28 ms 2872 KB Output is correct
59 Correct 30 ms 2876 KB Output is correct
60 Correct 28 ms 2908 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 6 ms 1112 KB Output is correct
15 Correct 10 ms 1884 KB Output is correct
16 Correct 16 ms 2648 KB Output is correct
17 Correct 14 ms 2652 KB Output is correct
18 Correct 16 ms 2816 KB Output is correct
19 Correct 15 ms 2652 KB Output is correct
20 Correct 17 ms 2648 KB Output is correct
21 Correct 15 ms 2652 KB Output is correct
22 Correct 16 ms 2812 KB Output is correct
23 Correct 16 ms 2648 KB Output is correct
24 Correct 19 ms 2652 KB Output is correct
25 Correct 15 ms 2652 KB Output is correct
26 Correct 1 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 6 ms 1116 KB Output is correct
30 Correct 12 ms 1884 KB Output is correct
31 Correct 18 ms 2652 KB Output is correct
32 Correct 17 ms 2904 KB Output is correct
33 Correct 20 ms 2648 KB Output is correct
34 Correct 23 ms 2812 KB Output is correct
35 Correct 18 ms 2660 KB Output is correct
36 Correct 19 ms 2652 KB Output is correct
37 Correct 18 ms 2648 KB Output is correct
38 Correct 17 ms 2652 KB Output is correct
39 Correct 18 ms 2652 KB Output is correct
40 Correct 18 ms 2652 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 1 ms 348 KB Output is correct
43 Correct 1 ms 348 KB Output is correct
44 Correct 1 ms 360 KB Output is correct
45 Correct 1 ms 348 KB Output is correct
46 Correct 2 ms 604 KB Output is correct
47 Correct 5 ms 860 KB Output is correct
48 Correct 5 ms 860 KB Output is correct
49 Correct 10 ms 1116 KB Output is correct
50 Correct 19 ms 2104 KB Output is correct
51 Correct 30 ms 2908 KB Output is correct
52 Correct 38 ms 2648 KB Output is correct
53 Correct 28 ms 2908 KB Output is correct
54 Correct 28 ms 3124 KB Output is correct
55 Correct 29 ms 2648 KB Output is correct
56 Correct 28 ms 2648 KB Output is correct
57 Correct 28 ms 2876 KB Output is correct
58 Correct 29 ms 2652 KB Output is correct
59 Correct 29 ms 2652 KB Output is correct
60 Correct 29 ms 2908 KB Output is correct
61 Correct 29 ms 2908 KB Output is correct
62 Correct 28 ms 2648 KB Output is correct
63 Correct 28 ms 2884 KB Output is correct
64 Correct 29 ms 2880 KB Output is correct
65 Correct 28 ms 2908 KB Output is correct
66 Correct 29 ms 2652 KB Output is correct
67 Correct 28 ms 2872 KB Output is correct
68 Correct 28 ms 2872 KB Output is correct
69 Correct 30 ms 2876 KB Output is correct
70 Correct 28 ms 2908 KB Output is correct
71 Correct 6 ms 856 KB Output is correct
72 Correct 6 ms 860 KB Output is correct
73 Correct 6 ms 860 KB Output is correct
74 Correct 6 ms 860 KB Output is correct
75 Correct 7 ms 1016 KB Output is correct
76 Correct 14 ms 1532 KB Output is correct
77 Correct 14 ms 1628 KB Output is correct
78 Correct 14 ms 1628 KB Output is correct
79 Correct 20 ms 1624 KB Output is correct
80 Correct 19 ms 1636 KB Output is correct
81 Correct 43 ms 2892 KB Output is correct
82 Correct 32 ms 2896 KB Output is correct
83 Correct 30 ms 2880 KB Output is correct
84 Correct 34 ms 2888 KB Output is correct
85 Correct 36 ms 2884 KB Output is correct
86 Correct 40 ms 3792 KB Output is correct
87 Correct 60 ms 3876 KB Output is correct
88 Correct 44 ms 3784 KB Output is correct
89 Correct 41 ms 3784 KB Output is correct
90 Correct 53 ms 3700 KB Output is correct
91 Correct 88 ms 11460 KB Output is correct
92 Correct 85 ms 12992 KB Output is correct
93 Correct 85 ms 12992 KB Output is correct
94 Correct 90 ms 13064 KB Output is correct
95 Correct 87 ms 13144 KB Output is correct
96 Correct 160 ms 22672 KB Output is correct
97 Correct 147 ms 22932 KB Output is correct
98 Correct 144 ms 22720 KB Output is correct
99 Correct 189 ms 22912 KB Output is correct
100 Correct 136 ms 22556 KB Output is correct
101 Correct 185 ms 22088 KB Output is correct
102 Correct 143 ms 22036 KB Output is correct
103 Correct 141 ms 21956 KB Output is correct
104 Correct 169 ms 21988 KB Output is correct
105 Correct 183 ms 21836 KB Output is correct
106 Correct 168 ms 26204 KB Output is correct
107 Correct 200 ms 26268 KB Output is correct
108 Correct 215 ms 26148 KB Output is correct
109 Correct 186 ms 26304 KB Output is correct
110 Correct 201 ms 26240 KB Output is correct
111 Correct 225 ms 26456 KB Output is correct
112 Correct 187 ms 26204 KB Output is correct
113 Correct 177 ms 26256 KB Output is correct
114 Correct 204 ms 26252 KB Output is correct
115 Correct 171 ms 26300 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 6 ms 1112 KB Output is correct
15 Correct 10 ms 1884 KB Output is correct
16 Correct 16 ms 2648 KB Output is correct
17 Correct 14 ms 2652 KB Output is correct
18 Correct 16 ms 2816 KB Output is correct
19 Correct 15 ms 2652 KB Output is correct
20 Correct 17 ms 2648 KB Output is correct
21 Correct 15 ms 2652 KB Output is correct
22 Correct 16 ms 2812 KB Output is correct
23 Correct 16 ms 2648 KB Output is correct
24 Correct 19 ms 2652 KB Output is correct
25 Correct 15 ms 2652 KB Output is correct
26 Correct 1 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 6 ms 1116 KB Output is correct
30 Correct 12 ms 1884 KB Output is correct
31 Correct 18 ms 2652 KB Output is correct
32 Correct 17 ms 2904 KB Output is correct
33 Correct 20 ms 2648 KB Output is correct
34 Correct 23 ms 2812 KB Output is correct
35 Correct 18 ms 2660 KB Output is correct
36 Correct 19 ms 2652 KB Output is correct
37 Correct 18 ms 2648 KB Output is correct
38 Correct 17 ms 2652 KB Output is correct
39 Correct 18 ms 2652 KB Output is correct
40 Correct 18 ms 2652 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 1 ms 348 KB Output is correct
43 Correct 1 ms 348 KB Output is correct
44 Correct 1 ms 360 KB Output is correct
45 Correct 1 ms 348 KB Output is correct
46 Correct 2 ms 604 KB Output is correct
47 Correct 5 ms 860 KB Output is correct
48 Correct 5 ms 860 KB Output is correct
49 Correct 10 ms 1116 KB Output is correct
50 Correct 19 ms 2104 KB Output is correct
51 Correct 30 ms 2908 KB Output is correct
52 Correct 38 ms 2648 KB Output is correct
53 Correct 28 ms 2908 KB Output is correct
54 Correct 28 ms 3124 KB Output is correct
55 Correct 29 ms 2648 KB Output is correct
56 Correct 28 ms 2648 KB Output is correct
57 Correct 28 ms 2876 KB Output is correct
58 Correct 29 ms 2652 KB Output is correct
59 Correct 29 ms 2652 KB Output is correct
60 Correct 29 ms 2908 KB Output is correct
61 Correct 29 ms 2908 KB Output is correct
62 Correct 28 ms 2648 KB Output is correct
63 Correct 28 ms 2884 KB Output is correct
64 Correct 29 ms 2880 KB Output is correct
65 Correct 28 ms 2908 KB Output is correct
66 Correct 29 ms 2652 KB Output is correct
67 Correct 28 ms 2872 KB Output is correct
68 Correct 28 ms 2872 KB Output is correct
69 Correct 30 ms 2876 KB Output is correct
70 Correct 28 ms 2908 KB Output is correct
71 Correct 6 ms 856 KB Output is correct
72 Correct 6 ms 860 KB Output is correct
73 Correct 6 ms 860 KB Output is correct
74 Correct 6 ms 860 KB Output is correct
75 Correct 7 ms 1016 KB Output is correct
76 Correct 14 ms 1532 KB Output is correct
77 Correct 14 ms 1628 KB Output is correct
78 Correct 14 ms 1628 KB Output is correct
79 Correct 20 ms 1624 KB Output is correct
80 Correct 19 ms 1636 KB Output is correct
81 Correct 43 ms 2892 KB Output is correct
82 Correct 32 ms 2896 KB Output is correct
83 Correct 30 ms 2880 KB Output is correct
84 Correct 34 ms 2888 KB Output is correct
85 Correct 36 ms 2884 KB Output is correct
86 Correct 40 ms 3792 KB Output is correct
87 Correct 60 ms 3876 KB Output is correct
88 Correct 44 ms 3784 KB Output is correct
89 Correct 41 ms 3784 KB Output is correct
90 Correct 53 ms 3700 KB Output is correct
91 Correct 88 ms 11460 KB Output is correct
92 Correct 85 ms 12992 KB Output is correct
93 Correct 85 ms 12992 KB Output is correct
94 Correct 90 ms 13064 KB Output is correct
95 Correct 87 ms 13144 KB Output is correct
96 Correct 160 ms 22672 KB Output is correct
97 Correct 147 ms 22932 KB Output is correct
98 Correct 144 ms 22720 KB Output is correct
99 Correct 189 ms 22912 KB Output is correct
100 Correct 136 ms 22556 KB Output is correct
101 Correct 185 ms 22088 KB Output is correct
102 Correct 143 ms 22036 KB Output is correct
103 Correct 141 ms 21956 KB Output is correct
104 Correct 169 ms 21988 KB Output is correct
105 Correct 183 ms 21836 KB Output is correct
106 Correct 168 ms 26204 KB Output is correct
107 Correct 200 ms 26268 KB Output is correct
108 Correct 215 ms 26148 KB Output is correct
109 Correct 186 ms 26304 KB Output is correct
110 Correct 201 ms 26240 KB Output is correct
111 Correct 225 ms 26456 KB Output is correct
112 Correct 187 ms 26204 KB Output is correct
113 Correct 177 ms 26256 KB Output is correct
114 Correct 204 ms 26252 KB Output is correct
115 Correct 171 ms 26300 KB Output is correct
116 Incorrect 76 ms 1612 KB Output isn't correct
117 Halted 0 ms 0 KB -