Submission #685047

# Submission time Handle Problem Language Result Execution time Memory
685047 2023-01-23T07:16:06 Z moonhero Diversity (CEOI21_diversity) C++14
64 / 100
7000 ms 38924 KB
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const long long N = 3e5 + 5;
long long a[N];
vector <long long> res;
long long cont (long long r) {
    return (r + 1) * (r) / 2;
}
signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    ll n, q; cin >> n >> q;
    map <ll, ll> ans, s;
    for (ll i = 1; i <= n; i++) {
        cin >> a[i];
        s[a[i]] = -1;
        ans[a[i]]++;
    } 
    while (q--) {
        ll l, r; cin >> l >> r;
        for (auto it : ans) res.push_back(it.second);
        ll h = 0, g = 0;
        sort(res.begin(), res.end());
        vector <int> rs(res.size());
        bool ok = 0;
        int lt = 0, rt = rs.size() - 1;
        for (auto it : res) {
            if (ok) rs[rt] = it, rt--, ok = 0;
            else rs[lt] = it, lt++, ok = 1;
        } 
        for (int i = 0; i < rs.size(); i++) res[i] = rs[i];
        ll pref = 0, sum = 0;
        for (int i = 0; i < res.size(); i++) {
            pref += res[i], sum += pref;
            // cout << sum << ' ' << res[i] << ' ' << i << '\n';
            h += res[i] * sum - cont(res[i] - 1);
        }
        cout << h << '\n';
    }
    return 0;
}

Compilation message

diversity.cpp: In function 'int main()':
diversity.cpp:32:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |         for (int i = 0; i < rs.size(); i++) res[i] = rs[i];
      |                         ~~^~~~~~~~~~~
diversity.cpp:34:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |         for (int i = 0; i < res.size(); i++) {
      |                         ~~^~~~~~~~~~~~
diversity.cpp:23:19: warning: unused variable 'g' [-Wunused-variable]
   23 |         ll h = 0, g = 0;
      |                   ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 7 ms 1108 KB Output is correct
5 Correct 14 ms 1876 KB Output is correct
6 Correct 20 ms 2644 KB Output is correct
7 Correct 18 ms 2532 KB Output is correct
8 Correct 19 ms 2644 KB Output is correct
9 Correct 20 ms 2644 KB Output is correct
10 Correct 19 ms 2640 KB Output is correct
11 Correct 25 ms 2644 KB Output is correct
12 Correct 20 ms 2572 KB Output is correct
13 Correct 21 ms 2652 KB Output is correct
14 Correct 20 ms 2644 KB Output is correct
15 Correct 27 ms 2568 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 7 ms 1108 KB Output is correct
5 Correct 14 ms 1876 KB Output is correct
6 Correct 20 ms 2644 KB Output is correct
7 Correct 18 ms 2532 KB Output is correct
8 Correct 19 ms 2644 KB Output is correct
9 Correct 20 ms 2644 KB Output is correct
10 Correct 19 ms 2640 KB Output is correct
11 Correct 25 ms 2644 KB Output is correct
12 Correct 20 ms 2572 KB Output is correct
13 Correct 21 ms 2652 KB Output is correct
14 Correct 20 ms 2644 KB Output is correct
15 Correct 27 ms 2568 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 8 ms 1116 KB Output is correct
20 Correct 15 ms 1872 KB Output is correct
21 Correct 25 ms 2560 KB Output is correct
22 Correct 23 ms 2556 KB Output is correct
23 Correct 22 ms 2644 KB Output is correct
24 Correct 29 ms 2576 KB Output is correct
25 Correct 24 ms 2640 KB Output is correct
26 Correct 24 ms 2644 KB Output is correct
27 Correct 24 ms 2556 KB Output is correct
28 Correct 22 ms 2588 KB Output is correct
29 Correct 24 ms 2632 KB Output is correct
30 Correct 29 ms 2656 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 7 ms 1108 KB Output is correct
5 Correct 14 ms 1876 KB Output is correct
6 Correct 20 ms 2644 KB Output is correct
7 Correct 18 ms 2532 KB Output is correct
8 Correct 19 ms 2644 KB Output is correct
9 Correct 20 ms 2644 KB Output is correct
10 Correct 19 ms 2640 KB Output is correct
11 Correct 25 ms 2644 KB Output is correct
12 Correct 20 ms 2572 KB Output is correct
13 Correct 21 ms 2652 KB Output is correct
14 Correct 20 ms 2644 KB Output is correct
15 Correct 27 ms 2568 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 8 ms 1116 KB Output is correct
20 Correct 15 ms 1872 KB Output is correct
21 Correct 25 ms 2560 KB Output is correct
22 Correct 23 ms 2556 KB Output is correct
23 Correct 22 ms 2644 KB Output is correct
24 Correct 29 ms 2576 KB Output is correct
25 Correct 24 ms 2640 KB Output is correct
26 Correct 24 ms 2644 KB Output is correct
27 Correct 24 ms 2556 KB Output is correct
28 Correct 22 ms 2588 KB Output is correct
29 Correct 24 ms 2632 KB Output is correct
30 Correct 29 ms 2656 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 2 ms 340 KB Output is correct
36 Correct 2 ms 468 KB Output is correct
37 Correct 7 ms 724 KB Output is correct
38 Correct 9 ms 816 KB Output is correct
39 Correct 15 ms 1236 KB Output is correct
40 Correct 30 ms 1920 KB Output is correct
41 Correct 46 ms 2700 KB Output is correct
42 Correct 54 ms 2672 KB Output is correct
43 Correct 54 ms 2756 KB Output is correct
44 Correct 44 ms 2768 KB Output is correct
45 Correct 44 ms 2768 KB Output is correct
46 Correct 44 ms 2768 KB Output is correct
47 Correct 44 ms 2780 KB Output is correct
48 Correct 47 ms 2712 KB Output is correct
49 Correct 54 ms 2780 KB Output is correct
50 Correct 46 ms 2696 KB Output is correct
51 Correct 56 ms 2672 KB Output is correct
52 Correct 43 ms 2764 KB Output is correct
53 Correct 44 ms 2736 KB Output is correct
54 Correct 48 ms 2700 KB Output is correct
55 Correct 44 ms 2772 KB Output is correct
56 Correct 43 ms 2760 KB Output is correct
57 Correct 44 ms 2740 KB Output is correct
58 Correct 47 ms 2764 KB Output is correct
59 Correct 45 ms 2776 KB Output is correct
60 Correct 45 ms 2672 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 7 ms 1108 KB Output is correct
15 Correct 14 ms 1876 KB Output is correct
16 Correct 20 ms 2644 KB Output is correct
17 Correct 18 ms 2532 KB Output is correct
18 Correct 19 ms 2644 KB Output is correct
19 Correct 20 ms 2644 KB Output is correct
20 Correct 19 ms 2640 KB Output is correct
21 Correct 25 ms 2644 KB Output is correct
22 Correct 20 ms 2572 KB Output is correct
23 Correct 21 ms 2652 KB Output is correct
24 Correct 20 ms 2644 KB Output is correct
25 Correct 27 ms 2568 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 8 ms 1116 KB Output is correct
30 Correct 15 ms 1872 KB Output is correct
31 Correct 25 ms 2560 KB Output is correct
32 Correct 23 ms 2556 KB Output is correct
33 Correct 22 ms 2644 KB Output is correct
34 Correct 29 ms 2576 KB Output is correct
35 Correct 24 ms 2640 KB Output is correct
36 Correct 24 ms 2644 KB Output is correct
37 Correct 24 ms 2556 KB Output is correct
38 Correct 22 ms 2588 KB Output is correct
39 Correct 24 ms 2632 KB Output is correct
40 Correct 29 ms 2656 KB Output is correct
41 Correct 1 ms 340 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 1 ms 340 KB Output is correct
45 Correct 2 ms 340 KB Output is correct
46 Correct 2 ms 468 KB Output is correct
47 Correct 7 ms 724 KB Output is correct
48 Correct 9 ms 816 KB Output is correct
49 Correct 15 ms 1236 KB Output is correct
50 Correct 30 ms 1920 KB Output is correct
51 Correct 46 ms 2700 KB Output is correct
52 Correct 54 ms 2672 KB Output is correct
53 Correct 54 ms 2756 KB Output is correct
54 Correct 44 ms 2768 KB Output is correct
55 Correct 44 ms 2768 KB Output is correct
56 Correct 44 ms 2768 KB Output is correct
57 Correct 44 ms 2780 KB Output is correct
58 Correct 47 ms 2712 KB Output is correct
59 Correct 54 ms 2780 KB Output is correct
60 Correct 46 ms 2696 KB Output is correct
61 Correct 56 ms 2672 KB Output is correct
62 Correct 43 ms 2764 KB Output is correct
63 Correct 44 ms 2736 KB Output is correct
64 Correct 48 ms 2700 KB Output is correct
65 Correct 44 ms 2772 KB Output is correct
66 Correct 43 ms 2760 KB Output is correct
67 Correct 44 ms 2740 KB Output is correct
68 Correct 47 ms 2764 KB Output is correct
69 Correct 45 ms 2776 KB Output is correct
70 Correct 45 ms 2672 KB Output is correct
71 Correct 10 ms 892 KB Output is correct
72 Correct 10 ms 908 KB Output is correct
73 Correct 9 ms 980 KB Output is correct
74 Correct 11 ms 980 KB Output is correct
75 Correct 9 ms 964 KB Output is correct
76 Correct 23 ms 1748 KB Output is correct
77 Correct 23 ms 1756 KB Output is correct
78 Correct 24 ms 1752 KB Output is correct
79 Correct 25 ms 1752 KB Output is correct
80 Correct 23 ms 1824 KB Output is correct
81 Correct 53 ms 3340 KB Output is correct
82 Correct 57 ms 3336 KB Output is correct
83 Correct 53 ms 3304 KB Output is correct
84 Correct 52 ms 3276 KB Output is correct
85 Correct 54 ms 3328 KB Output is correct
86 Correct 69 ms 4756 KB Output is correct
87 Correct 66 ms 4752 KB Output is correct
88 Correct 75 ms 4748 KB Output is correct
89 Correct 79 ms 4712 KB Output is correct
90 Correct 64 ms 4684 KB Output is correct
91 Correct 195 ms 16324 KB Output is correct
92 Correct 208 ms 16328 KB Output is correct
93 Correct 204 ms 16320 KB Output is correct
94 Correct 196 ms 16296 KB Output is correct
95 Correct 232 ms 16320 KB Output is correct
96 Correct 304 ms 29948 KB Output is correct
97 Correct 294 ms 31852 KB Output is correct
98 Correct 333 ms 31952 KB Output is correct
99 Correct 322 ms 31936 KB Output is correct
100 Correct 305 ms 31868 KB Output is correct
101 Correct 296 ms 31908 KB Output is correct
102 Correct 302 ms 31872 KB Output is correct
103 Correct 307 ms 31960 KB Output is correct
104 Correct 296 ms 31908 KB Output is correct
105 Correct 296 ms 31852 KB Output is correct
106 Correct 341 ms 38776 KB Output is correct
107 Correct 344 ms 38728 KB Output is correct
108 Correct 336 ms 38776 KB Output is correct
109 Correct 341 ms 38792 KB Output is correct
110 Correct 347 ms 38924 KB Output is correct
111 Correct 333 ms 38840 KB Output is correct
112 Correct 334 ms 38808 KB Output is correct
113 Correct 333 ms 38840 KB Output is correct
114 Correct 354 ms 38804 KB Output is correct
115 Correct 331 ms 38824 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 7 ms 1108 KB Output is correct
15 Correct 14 ms 1876 KB Output is correct
16 Correct 20 ms 2644 KB Output is correct
17 Correct 18 ms 2532 KB Output is correct
18 Correct 19 ms 2644 KB Output is correct
19 Correct 20 ms 2644 KB Output is correct
20 Correct 19 ms 2640 KB Output is correct
21 Correct 25 ms 2644 KB Output is correct
22 Correct 20 ms 2572 KB Output is correct
23 Correct 21 ms 2652 KB Output is correct
24 Correct 20 ms 2644 KB Output is correct
25 Correct 27 ms 2568 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 8 ms 1116 KB Output is correct
30 Correct 15 ms 1872 KB Output is correct
31 Correct 25 ms 2560 KB Output is correct
32 Correct 23 ms 2556 KB Output is correct
33 Correct 22 ms 2644 KB Output is correct
34 Correct 29 ms 2576 KB Output is correct
35 Correct 24 ms 2640 KB Output is correct
36 Correct 24 ms 2644 KB Output is correct
37 Correct 24 ms 2556 KB Output is correct
38 Correct 22 ms 2588 KB Output is correct
39 Correct 24 ms 2632 KB Output is correct
40 Correct 29 ms 2656 KB Output is correct
41 Correct 1 ms 340 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 1 ms 340 KB Output is correct
45 Correct 2 ms 340 KB Output is correct
46 Correct 2 ms 468 KB Output is correct
47 Correct 7 ms 724 KB Output is correct
48 Correct 9 ms 816 KB Output is correct
49 Correct 15 ms 1236 KB Output is correct
50 Correct 30 ms 1920 KB Output is correct
51 Correct 46 ms 2700 KB Output is correct
52 Correct 54 ms 2672 KB Output is correct
53 Correct 54 ms 2756 KB Output is correct
54 Correct 44 ms 2768 KB Output is correct
55 Correct 44 ms 2768 KB Output is correct
56 Correct 44 ms 2768 KB Output is correct
57 Correct 44 ms 2780 KB Output is correct
58 Correct 47 ms 2712 KB Output is correct
59 Correct 54 ms 2780 KB Output is correct
60 Correct 46 ms 2696 KB Output is correct
61 Correct 56 ms 2672 KB Output is correct
62 Correct 43 ms 2764 KB Output is correct
63 Correct 44 ms 2736 KB Output is correct
64 Correct 48 ms 2700 KB Output is correct
65 Correct 44 ms 2772 KB Output is correct
66 Correct 43 ms 2760 KB Output is correct
67 Correct 44 ms 2740 KB Output is correct
68 Correct 47 ms 2764 KB Output is correct
69 Correct 45 ms 2776 KB Output is correct
70 Correct 45 ms 2672 KB Output is correct
71 Correct 10 ms 892 KB Output is correct
72 Correct 10 ms 908 KB Output is correct
73 Correct 9 ms 980 KB Output is correct
74 Correct 11 ms 980 KB Output is correct
75 Correct 9 ms 964 KB Output is correct
76 Correct 23 ms 1748 KB Output is correct
77 Correct 23 ms 1756 KB Output is correct
78 Correct 24 ms 1752 KB Output is correct
79 Correct 25 ms 1752 KB Output is correct
80 Correct 23 ms 1824 KB Output is correct
81 Correct 53 ms 3340 KB Output is correct
82 Correct 57 ms 3336 KB Output is correct
83 Correct 53 ms 3304 KB Output is correct
84 Correct 52 ms 3276 KB Output is correct
85 Correct 54 ms 3328 KB Output is correct
86 Correct 69 ms 4756 KB Output is correct
87 Correct 66 ms 4752 KB Output is correct
88 Correct 75 ms 4748 KB Output is correct
89 Correct 79 ms 4712 KB Output is correct
90 Correct 64 ms 4684 KB Output is correct
91 Correct 195 ms 16324 KB Output is correct
92 Correct 208 ms 16328 KB Output is correct
93 Correct 204 ms 16320 KB Output is correct
94 Correct 196 ms 16296 KB Output is correct
95 Correct 232 ms 16320 KB Output is correct
96 Correct 304 ms 29948 KB Output is correct
97 Correct 294 ms 31852 KB Output is correct
98 Correct 333 ms 31952 KB Output is correct
99 Correct 322 ms 31936 KB Output is correct
100 Correct 305 ms 31868 KB Output is correct
101 Correct 296 ms 31908 KB Output is correct
102 Correct 302 ms 31872 KB Output is correct
103 Correct 307 ms 31960 KB Output is correct
104 Correct 296 ms 31908 KB Output is correct
105 Correct 296 ms 31852 KB Output is correct
106 Correct 341 ms 38776 KB Output is correct
107 Correct 344 ms 38728 KB Output is correct
108 Correct 336 ms 38776 KB Output is correct
109 Correct 341 ms 38792 KB Output is correct
110 Correct 347 ms 38924 KB Output is correct
111 Correct 333 ms 38840 KB Output is correct
112 Correct 334 ms 38808 KB Output is correct
113 Correct 333 ms 38840 KB Output is correct
114 Correct 354 ms 38804 KB Output is correct
115 Correct 331 ms 38824 KB Output is correct
116 Execution timed out 7026 ms 3476 KB Time limit exceeded
117 Halted 0 ms 0 KB -