Submission #957312

# Submission time Handle Problem Language Result Execution time Memory
957312 2024-04-03T13:21:14 Z LucaIlie Diversity (CEOI21_diversity) C++17
64 / 100
7000 ms 16320 KB
#include <bits/stdc++.h>

using namespace std;

const int MAX_N = 3e5;
int a[MAX_N + 1];

long long gauss( int n ) {
    return (long long)n * (n + 1) / 2;
}

int main() {
    int n, q;

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

    while ( q-- ) {
        int l, r;
        cin >> l >> r;

        unordered_map<int, int> mp;
        for ( int i = l; i <= r; i++ )
            mp[a[i]]++;

        vector<int> v;
        for ( auto p: mp )
            v.push_back( p.second );

        sort( v.begin(), v.end() );
        vector<int> f( v.size() );
        for ( int i = 0; i < v.size(); i++ ) {
            if ( i % 2 == 0 )
                f[i / 2] = v[i];
            else
                f[v.size() - 1 - i / 2] = v[i];
        }

        int n = r - l + 1;
        long long ans = 0, k = 0;
        for ( int i = 0; i < f.size(); i++ ) {
            ans = ans + gauss( n - k ) - gauss( n - k - f[i] ) + (long long)k * (n - k);
            k += f[i];
        }

        cout << ans << "\n";
    }

    return 0;
}

Compilation message

diversity.cpp: In function 'int main()':
diversity.cpp:33:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |         for ( int i = 0; i < v.size(); i++ ) {
      |                          ~~^~~~~~~~~~
diversity.cpp:42:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |         for ( int i = 0; i < f.size(); i++ ) {
      |                          ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 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 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory 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 11 ms 604 KB Output is correct
5 Correct 23 ms 1104 KB Output is correct
6 Correct 36 ms 1584 KB Output is correct
7 Correct 34 ms 2128 KB Output is correct
8 Correct 36 ms 2132 KB Output is correct
9 Correct 35 ms 2132 KB Output is correct
10 Correct 36 ms 2236 KB Output is correct
11 Correct 35 ms 2152 KB Output is correct
12 Correct 35 ms 2128 KB Output is correct
13 Correct 35 ms 2140 KB Output is correct
14 Correct 40 ms 2136 KB Output is correct
15 Correct 35 ms 2132 KB Output is correct
# Verdict Execution time Memory 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 11 ms 604 KB Output is correct
5 Correct 23 ms 1104 KB Output is correct
6 Correct 36 ms 1584 KB Output is correct
7 Correct 34 ms 2128 KB Output is correct
8 Correct 36 ms 2132 KB Output is correct
9 Correct 35 ms 2132 KB Output is correct
10 Correct 36 ms 2236 KB Output is correct
11 Correct 35 ms 2152 KB Output is correct
12 Correct 35 ms 2128 KB Output is correct
13 Correct 35 ms 2140 KB Output is correct
14 Correct 40 ms 2136 KB Output is correct
15 Correct 35 ms 2132 KB Output is correct
16 Correct 1 ms 544 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 2 ms 344 KB Output is correct
19 Correct 14 ms 860 KB Output is correct
20 Correct 27 ms 1708 KB Output is correct
21 Correct 39 ms 2292 KB Output is correct
22 Correct 40 ms 2260 KB Output is correct
23 Correct 42 ms 2388 KB Output is correct
24 Correct 48 ms 2236 KB Output is correct
25 Correct 39 ms 2328 KB Output is correct
26 Correct 39 ms 2132 KB Output is correct
27 Correct 39 ms 2132 KB Output is correct
28 Correct 37 ms 2128 KB Output is correct
29 Correct 38 ms 2128 KB Output is correct
30 Correct 47 ms 2388 KB Output is correct
# Verdict Execution time Memory 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 11 ms 604 KB Output is correct
5 Correct 23 ms 1104 KB Output is correct
6 Correct 36 ms 1584 KB Output is correct
7 Correct 34 ms 2128 KB Output is correct
8 Correct 36 ms 2132 KB Output is correct
9 Correct 35 ms 2132 KB Output is correct
10 Correct 36 ms 2236 KB Output is correct
11 Correct 35 ms 2152 KB Output is correct
12 Correct 35 ms 2128 KB Output is correct
13 Correct 35 ms 2140 KB Output is correct
14 Correct 40 ms 2136 KB Output is correct
15 Correct 35 ms 2132 KB Output is correct
16 Correct 1 ms 544 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 2 ms 344 KB Output is correct
19 Correct 14 ms 860 KB Output is correct
20 Correct 27 ms 1708 KB Output is correct
21 Correct 39 ms 2292 KB Output is correct
22 Correct 40 ms 2260 KB Output is correct
23 Correct 42 ms 2388 KB Output is correct
24 Correct 48 ms 2236 KB Output is correct
25 Correct 39 ms 2328 KB Output is correct
26 Correct 39 ms 2132 KB Output is correct
27 Correct 39 ms 2132 KB Output is correct
28 Correct 37 ms 2128 KB Output is correct
29 Correct 38 ms 2128 KB Output is correct
30 Correct 47 ms 2388 KB Output is correct
31 Correct 1 ms 344 KB Output is correct
32 Correct 1 ms 344 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 2 ms 348 KB Output is correct
35 Correct 2 ms 348 KB Output is correct
36 Correct 3 ms 348 KB Output is correct
37 Correct 8 ms 600 KB Output is correct
38 Correct 8 ms 856 KB Output is correct
39 Correct 18 ms 1116 KB Output is correct
40 Correct 31 ms 1872 KB Output is correct
41 Correct 47 ms 2640 KB Output is correct
42 Correct 46 ms 2776 KB Output is correct
43 Correct 46 ms 2648 KB Output is correct
44 Correct 48 ms 2896 KB Output is correct
45 Correct 47 ms 2640 KB Output is correct
46 Correct 46 ms 2740 KB Output is correct
47 Correct 46 ms 2640 KB Output is correct
48 Correct 46 ms 2684 KB Output is correct
49 Correct 48 ms 2576 KB Output is correct
50 Correct 46 ms 2644 KB Output is correct
51 Correct 46 ms 2640 KB Output is correct
52 Correct 46 ms 2604 KB Output is correct
53 Correct 47 ms 2556 KB Output is correct
54 Correct 53 ms 2760 KB Output is correct
55 Correct 58 ms 2772 KB Output is correct
56 Correct 46 ms 2644 KB Output is correct
57 Correct 45 ms 2776 KB Output is correct
58 Correct 50 ms 2736 KB Output is correct
59 Correct 49 ms 2644 KB Output is correct
60 Correct 46 ms 2644 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 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 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 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 11 ms 604 KB Output is correct
15 Correct 23 ms 1104 KB Output is correct
16 Correct 36 ms 1584 KB Output is correct
17 Correct 34 ms 2128 KB Output is correct
18 Correct 36 ms 2132 KB Output is correct
19 Correct 35 ms 2132 KB Output is correct
20 Correct 36 ms 2236 KB Output is correct
21 Correct 35 ms 2152 KB Output is correct
22 Correct 35 ms 2128 KB Output is correct
23 Correct 35 ms 2140 KB Output is correct
24 Correct 40 ms 2136 KB Output is correct
25 Correct 35 ms 2132 KB Output is correct
26 Correct 1 ms 544 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 2 ms 344 KB Output is correct
29 Correct 14 ms 860 KB Output is correct
30 Correct 27 ms 1708 KB Output is correct
31 Correct 39 ms 2292 KB Output is correct
32 Correct 40 ms 2260 KB Output is correct
33 Correct 42 ms 2388 KB Output is correct
34 Correct 48 ms 2236 KB Output is correct
35 Correct 39 ms 2328 KB Output is correct
36 Correct 39 ms 2132 KB Output is correct
37 Correct 39 ms 2132 KB Output is correct
38 Correct 37 ms 2128 KB Output is correct
39 Correct 38 ms 2128 KB Output is correct
40 Correct 47 ms 2388 KB Output is correct
41 Correct 1 ms 344 KB Output is correct
42 Correct 1 ms 344 KB Output is correct
43 Correct 1 ms 348 KB Output is correct
44 Correct 2 ms 348 KB Output is correct
45 Correct 2 ms 348 KB Output is correct
46 Correct 3 ms 348 KB Output is correct
47 Correct 8 ms 600 KB Output is correct
48 Correct 8 ms 856 KB Output is correct
49 Correct 18 ms 1116 KB Output is correct
50 Correct 31 ms 1872 KB Output is correct
51 Correct 47 ms 2640 KB Output is correct
52 Correct 46 ms 2776 KB Output is correct
53 Correct 46 ms 2648 KB Output is correct
54 Correct 48 ms 2896 KB Output is correct
55 Correct 47 ms 2640 KB Output is correct
56 Correct 46 ms 2740 KB Output is correct
57 Correct 46 ms 2640 KB Output is correct
58 Correct 46 ms 2684 KB Output is correct
59 Correct 48 ms 2576 KB Output is correct
60 Correct 46 ms 2644 KB Output is correct
61 Correct 46 ms 2640 KB Output is correct
62 Correct 46 ms 2604 KB Output is correct
63 Correct 47 ms 2556 KB Output is correct
64 Correct 53 ms 2760 KB Output is correct
65 Correct 58 ms 2772 KB Output is correct
66 Correct 46 ms 2644 KB Output is correct
67 Correct 45 ms 2776 KB Output is correct
68 Correct 50 ms 2736 KB Output is correct
69 Correct 49 ms 2644 KB Output is correct
70 Correct 46 ms 2644 KB Output is correct
71 Correct 9 ms 860 KB Output is correct
72 Correct 9 ms 812 KB Output is correct
73 Correct 9 ms 860 KB Output is correct
74 Correct 9 ms 860 KB Output is correct
75 Correct 9 ms 860 KB Output is correct
76 Correct 24 ms 1348 KB Output is correct
77 Correct 19 ms 1372 KB Output is correct
78 Correct 19 ms 1368 KB Output is correct
79 Correct 18 ms 1480 KB Output is correct
80 Correct 19 ms 1372 KB Output is correct
81 Correct 40 ms 2412 KB Output is correct
82 Correct 38 ms 2436 KB Output is correct
83 Correct 37 ms 2640 KB Output is correct
84 Correct 38 ms 2644 KB Output is correct
85 Correct 38 ms 2644 KB Output is correct
86 Correct 40 ms 3080 KB Output is correct
87 Correct 48 ms 3152 KB Output is correct
88 Correct 41 ms 3156 KB Output is correct
89 Correct 41 ms 3144 KB Output is correct
90 Correct 48 ms 3236 KB Output is correct
91 Correct 72 ms 8648 KB Output is correct
92 Correct 72 ms 8648 KB Output is correct
93 Correct 73 ms 8596 KB Output is correct
94 Correct 73 ms 8636 KB Output is correct
95 Correct 78 ms 8648 KB Output is correct
96 Correct 88 ms 14204 KB Output is correct
97 Correct 96 ms 14304 KB Output is correct
98 Correct 89 ms 14188 KB Output is correct
99 Correct 89 ms 14260 KB Output is correct
100 Correct 96 ms 14192 KB Output is correct
101 Correct 87 ms 14208 KB Output is correct
102 Correct 93 ms 14208 KB Output is correct
103 Correct 96 ms 14176 KB Output is correct
104 Correct 88 ms 14184 KB Output is correct
105 Correct 96 ms 14084 KB Output is correct
106 Correct 94 ms 16012 KB Output is correct
107 Correct 100 ms 15996 KB Output is correct
108 Correct 91 ms 15872 KB Output is correct
109 Correct 92 ms 16000 KB Output is correct
110 Correct 100 ms 16068 KB Output is correct
111 Correct 101 ms 16320 KB Output is correct
112 Correct 92 ms 15992 KB Output is correct
113 Correct 102 ms 15984 KB Output is correct
114 Correct 97 ms 15912 KB Output is correct
115 Correct 93 ms 16000 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 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 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 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 11 ms 604 KB Output is correct
15 Correct 23 ms 1104 KB Output is correct
16 Correct 36 ms 1584 KB Output is correct
17 Correct 34 ms 2128 KB Output is correct
18 Correct 36 ms 2132 KB Output is correct
19 Correct 35 ms 2132 KB Output is correct
20 Correct 36 ms 2236 KB Output is correct
21 Correct 35 ms 2152 KB Output is correct
22 Correct 35 ms 2128 KB Output is correct
23 Correct 35 ms 2140 KB Output is correct
24 Correct 40 ms 2136 KB Output is correct
25 Correct 35 ms 2132 KB Output is correct
26 Correct 1 ms 544 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 2 ms 344 KB Output is correct
29 Correct 14 ms 860 KB Output is correct
30 Correct 27 ms 1708 KB Output is correct
31 Correct 39 ms 2292 KB Output is correct
32 Correct 40 ms 2260 KB Output is correct
33 Correct 42 ms 2388 KB Output is correct
34 Correct 48 ms 2236 KB Output is correct
35 Correct 39 ms 2328 KB Output is correct
36 Correct 39 ms 2132 KB Output is correct
37 Correct 39 ms 2132 KB Output is correct
38 Correct 37 ms 2128 KB Output is correct
39 Correct 38 ms 2128 KB Output is correct
40 Correct 47 ms 2388 KB Output is correct
41 Correct 1 ms 344 KB Output is correct
42 Correct 1 ms 344 KB Output is correct
43 Correct 1 ms 348 KB Output is correct
44 Correct 2 ms 348 KB Output is correct
45 Correct 2 ms 348 KB Output is correct
46 Correct 3 ms 348 KB Output is correct
47 Correct 8 ms 600 KB Output is correct
48 Correct 8 ms 856 KB Output is correct
49 Correct 18 ms 1116 KB Output is correct
50 Correct 31 ms 1872 KB Output is correct
51 Correct 47 ms 2640 KB Output is correct
52 Correct 46 ms 2776 KB Output is correct
53 Correct 46 ms 2648 KB Output is correct
54 Correct 48 ms 2896 KB Output is correct
55 Correct 47 ms 2640 KB Output is correct
56 Correct 46 ms 2740 KB Output is correct
57 Correct 46 ms 2640 KB Output is correct
58 Correct 46 ms 2684 KB Output is correct
59 Correct 48 ms 2576 KB Output is correct
60 Correct 46 ms 2644 KB Output is correct
61 Correct 46 ms 2640 KB Output is correct
62 Correct 46 ms 2604 KB Output is correct
63 Correct 47 ms 2556 KB Output is correct
64 Correct 53 ms 2760 KB Output is correct
65 Correct 58 ms 2772 KB Output is correct
66 Correct 46 ms 2644 KB Output is correct
67 Correct 45 ms 2776 KB Output is correct
68 Correct 50 ms 2736 KB Output is correct
69 Correct 49 ms 2644 KB Output is correct
70 Correct 46 ms 2644 KB Output is correct
71 Correct 9 ms 860 KB Output is correct
72 Correct 9 ms 812 KB Output is correct
73 Correct 9 ms 860 KB Output is correct
74 Correct 9 ms 860 KB Output is correct
75 Correct 9 ms 860 KB Output is correct
76 Correct 24 ms 1348 KB Output is correct
77 Correct 19 ms 1372 KB Output is correct
78 Correct 19 ms 1368 KB Output is correct
79 Correct 18 ms 1480 KB Output is correct
80 Correct 19 ms 1372 KB Output is correct
81 Correct 40 ms 2412 KB Output is correct
82 Correct 38 ms 2436 KB Output is correct
83 Correct 37 ms 2640 KB Output is correct
84 Correct 38 ms 2644 KB Output is correct
85 Correct 38 ms 2644 KB Output is correct
86 Correct 40 ms 3080 KB Output is correct
87 Correct 48 ms 3152 KB Output is correct
88 Correct 41 ms 3156 KB Output is correct
89 Correct 41 ms 3144 KB Output is correct
90 Correct 48 ms 3236 KB Output is correct
91 Correct 72 ms 8648 KB Output is correct
92 Correct 72 ms 8648 KB Output is correct
93 Correct 73 ms 8596 KB Output is correct
94 Correct 73 ms 8636 KB Output is correct
95 Correct 78 ms 8648 KB Output is correct
96 Correct 88 ms 14204 KB Output is correct
97 Correct 96 ms 14304 KB Output is correct
98 Correct 89 ms 14188 KB Output is correct
99 Correct 89 ms 14260 KB Output is correct
100 Correct 96 ms 14192 KB Output is correct
101 Correct 87 ms 14208 KB Output is correct
102 Correct 93 ms 14208 KB Output is correct
103 Correct 96 ms 14176 KB Output is correct
104 Correct 88 ms 14184 KB Output is correct
105 Correct 96 ms 14084 KB Output is correct
106 Correct 94 ms 16012 KB Output is correct
107 Correct 100 ms 15996 KB Output is correct
108 Correct 91 ms 15872 KB Output is correct
109 Correct 92 ms 16000 KB Output is correct
110 Correct 100 ms 16068 KB Output is correct
111 Correct 101 ms 16320 KB Output is correct
112 Correct 92 ms 15992 KB Output is correct
113 Correct 102 ms 15984 KB Output is correct
114 Correct 97 ms 15912 KB Output is correct
115 Correct 93 ms 16000 KB Output is correct
116 Correct 980 ms 1716 KB Output is correct
117 Correct 1212 ms 1540 KB Output is correct
118 Correct 4070 ms 2120 KB Output is correct
119 Correct 6068 ms 2336 KB Output is correct
120 Execution timed out 7039 ms 2120 KB Time limit exceeded
121 Halted 0 ms 0 KB -