Submission #957311

# Submission time Handle Problem Language Result Execution time Memory
957311 2024-04-03T13:20:45 Z LucaIlie Diversity (CEOI21_diversity) C++17
4 / 100
25 ms 2644 KB
#include <bits/stdc++.h>

using namespace std;

const int MAX_N = 2e5;
const int MAX_A = 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:34:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |         for ( int i = 0; i < v.size(); i++ ) {
      |                          ~~^~~~~~~~~~
diversity.cpp:43:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |         for ( int i = 0; i < f.size(); i++ ) {
      |                          ~~^~~~~~~~~~
# 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 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 452 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 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 2 ms 344 KB Output is correct
4 Correct 12 ms 900 KB Output is correct
5 Correct 23 ms 1368 KB Output is correct
6 Runtime error 25 ms 2644 KB Execution killed with signal 11
7 Halted 0 ms 0 KB -
# 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 2 ms 344 KB Output is correct
4 Correct 12 ms 900 KB Output is correct
5 Correct 23 ms 1368 KB Output is correct
6 Runtime error 25 ms 2644 KB Execution killed with signal 11
7 Halted 0 ms 0 KB -
# 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 2 ms 344 KB Output is correct
4 Correct 12 ms 900 KB Output is correct
5 Correct 23 ms 1368 KB Output is correct
6 Runtime error 25 ms 2644 KB Execution killed with signal 11
7 Halted 0 ms 0 KB -
# 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 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 452 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 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 2 ms 344 KB Output is correct
14 Correct 12 ms 900 KB Output is correct
15 Correct 23 ms 1368 KB Output is correct
16 Runtime error 25 ms 2644 KB Execution killed with signal 11
17 Halted 0 ms 0 KB -
# 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 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 452 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 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 2 ms 344 KB Output is correct
14 Correct 12 ms 900 KB Output is correct
15 Correct 23 ms 1368 KB Output is correct
16 Runtime error 25 ms 2644 KB Execution killed with signal 11
17 Halted 0 ms 0 KB -