Submission #957305

# Submission time Handle Problem Language Result Execution time Memory
957305 2024-04-03T12:54:53 Z LucaIlie Diversity (CEOI21_diversity) C++17
0 / 100
1 ms 600 KB
#include <bits/stdc++.h>

using namespace std;

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

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;

        vector<int> b;
        b.push_back( 0 );
        for ( int i = l; i <= r; i++ )
            b.push_back( a[i] );

        sort( b.begin(), b.end() );

        long long ans = 0;
        for ( int i = 1; i < b.size(); i++ ) {
            int p = (b[i] != b[i - 1] ? 0 : i - 1);
            ans += (i - p) * (b.size() - i);
        }

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

    return 0;
}

Compilation message

diversity.cpp: In function 'int main()':
diversity.cpp:27:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |         for ( int i = 1; i < b.size(); i++ ) {
      |                          ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 0 ms 600 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 0 ms 600 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 0 ms 600 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -