답안 #1090821

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1090821 2024-09-18T20:03:26 Z farica Diversity (CEOI21_diversity) C++14
0 / 100
10 ms 860 KB
#include <bits/stdc++.h>
#define ll long long

using namespace std;

const int MAX_N = 3e5;

int b[MAX_N + 5];

void solve() {
    int n, q;
    cin >> n >> q;
    set<int>s;
    for(int i=0; i<n; ++i) {
        int x;
        cin >> x;
        ++b[x];
        s.insert(x);
    }
    int L, R;
    cin >> L >> R;
    ll ans = 0, cnt = 0, cnt2 = 0;
    vector<int>v;
    for(auto it = s.begin(); it != s.end(); ++it) v.push_back(b[*it]);
    sort(v.begin(), v.end());
    int last = 0;
    for(int i=1; i<v.size(); i+=2) {
        last = i;
        int cur = v[i];
        cnt += cnt2;
        cnt2 += cur;
        ans += (cur * (cur + 1))/2;
        ans += cnt * cur;
        cnt += cur;
    }
    if((v.size()-2) == last) ++last;
    else --last;
    for(int i=last; i>=0; i -= 2) {
        int cur = v[i];
        cnt += cnt2;
        cnt2 += cur;
        ans += (cur * (cur + 1))/2;
        ans += cnt * cur;
        cnt += cur;
    }
    cout << ans << endl;
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

    int t = 1;
    while(t--) solve();

    return 0;
}

Compilation message

diversity.cpp: In function 'void solve()':
diversity.cpp:27:19: 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<v.size(); i+=2) {
      |                  ~^~~~~~~~~
diversity.cpp:36:21: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   36 |     if((v.size()-2) == last) ++last;
      |        ~~~~~~~~~~~~~^~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 464 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 5 ms 656 KB Output is correct
5 Incorrect 10 ms 860 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 464 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 5 ms 656 KB Output is correct
5 Incorrect 10 ms 860 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 464 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 5 ms 656 KB Output is correct
5 Incorrect 10 ms 860 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -