답안 #713128

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
713128 2023-03-21T08:22:02 Z Pety Diversity (CEOI21_diversity) C++14
0 / 100
1 ms 340 KB
#include <bits/stdc++.h>

using namespace std;

int n, a[300002], q, l, r, fr[300002], pref[300002], suf[300002];

int main () 
{
  ios_base::sync_with_stdio(false);
  cin.tie(0); cout.tie(0);
  cin >> n >> q;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    fr[a[i]]++;
  }
  cin >> l >> r;
  vector<pair<int, int>>a, b;
  for (int i = 1; i <= 300000; i++)
    if (fr[i])
      a.push_back({fr[i], i});
  sort(a.begin(), a.end());
  b.push_back({0, 0});
  for (int i = 0; i < a.size(); i += 2)
    b.push_back(a[i]);
  for (int i = (a.size() % 2 ? a.size() - 2 : a.size() - 1); i >= 0; i -= 2)
    b.push_back(a[i]);
  for (int i = 1; i < b.size(); i++)
    pref[i] = pref[i - 1] + b[i].first;
  for (int i = b.size() - 1; i >= 1; i--)
    suf[i] = suf[i + 1] + b[i].first;
  long long ans = 0;
  for (int i = 1; i < b.size(); i++) {
    ans += 1ll * pref[i - 1] * pref[i - 1] + 1ll * suf[i + 1] * suf[i + 1];
  }
  cout << ans;
  return 0;
}

Compilation message

diversity.cpp: In function 'int main()':
diversity.cpp:23:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |   for (int i = 0; i < a.size(); i += 2)
      |                   ~~^~~~~~~~~~
diversity.cpp:27:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |   for (int i = 1; i < b.size(); i++)
      |                   ~~^~~~~~~~~~
diversity.cpp:32:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |   for (int i = 1; i < b.size(); i++) {
      |                   ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -