답안 #857921

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
857921 2023-10-07T07:21:29 Z danikoynov Diversity (CEOI21_diversity) C++14
0 / 100
1 ms 2496 KB
#include<bits/stdc++.h>
#define endl '\n'

using namespace std;
typedef long long ll;

void speed()
{
    ios_base::sync_with_stdio(NULL);
    cin.tie(NULL);
    cout.tie(NULL);
}

const int maxn = 3e5 + 10;

int n, q, a[maxn], cnt[maxn];
void solve()
{
    cin >> n >> q;
    for (int i = 1; i <= n; i ++)
        cin >> a[i];

    int l, r;
    cin >> l >> r;

    for (int i = 1; i <= n; i ++)
        cnt[a[i]] ++;

    vector < ll > groups;
    for (int i = 1; i <= n; i ++)
        if (cnt[i] > 0)
        groups.push_back((ll)(cnt[i]));

    sort(groups.begin(), groups.end());
    ll ans = 0;
    for (ll i = 0; i < groups.size(); i ++)
        for (ll j = i + 1; j < groups.size(); j ++)
    {
        ans = ans + groups[i] * groups[j] * (j - i + 1);
    }

    for (int i = 0; i < groups.size(); i ++)
    {
        ll cur = groups[i];
        ans = ans + cur * (cur + 1) / 2;
    }

    cout << ans << endl;
}

int main()
{
    solve();
    return 0;
}
/**
4 1
1 1 1 1
1 2
2 4

*/

Compilation message

diversity.cpp: In function 'void solve()':
diversity.cpp:36:22: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |     for (ll i = 0; i < groups.size(); i ++)
      |                    ~~^~~~~~~~~~~~~~~
diversity.cpp:37:30: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |         for (ll j = i + 1; j < groups.size(); j ++)
      |                            ~~^~~~~~~~~~~~~~~
diversity.cpp:42:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |     for (int i = 0; i < groups.size(); i ++)
      |                     ~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2496 KB Output is correct
4 Incorrect 1 ms 2392 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 2396 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 2396 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 2396 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2496 KB Output is correct
4 Incorrect 1 ms 2392 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2496 KB Output is correct
4 Incorrect 1 ms 2392 KB Output isn't correct
5 Halted 0 ms 0 KB -