답안 #708153

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
708153 2023-03-11T07:16:50 Z vjudge1 Diversity (CEOI21_diversity) C++11
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>

using namespace std;
using LL = long long;

int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  int n, q;
  cin >> n >> q;
  vector<int> A(n);
  map<int, int> M;
  for (int &a : A) cin >> a, M[a] = 0;

  int k = 0;
  for (auto &p : M) p.second = k++;
  vector<LL> cnt(k);
  for (int &a : A) a = M[a], ++cnt[a];

  int L, R;
  cin >> L >> R;
  assert(q == 1 && L == 1 && R == n);

  LL ans = 0;
  for (int c : cnt) ans += c * (c + 1) / 2 + c * (n - c);
  sort(cnt.begin(), cnt.end());
  LL l = 0, r = 0, gi = 1;
  LL G[2], gi = 0;
  for (int c : cnt) {
    ans += G[gi] * (n - c - G[gi]), G[gi] += c;
    // if (gi)
    //   ans += l * (n - c - l), l += c;
    // else
    //   ans += r * (n - c - r), r += c;
    gi ^= 1;
  }
  cout << ans << '\n';
  return 0;
}

Compilation message

diversity.cpp: In function 'int main()':
diversity.cpp:27:12: error: redeclaration of 'LL gi'
   27 |   LL G[2], gi = 0;
      |            ^~
diversity.cpp:26:20: note: 'LL gi' previously declared here
   26 |   LL l = 0, r = 0, gi = 1;
      |                    ^~
diversity.cpp:26:6: warning: unused variable 'l' [-Wunused-variable]
   26 |   LL l = 0, r = 0, gi = 1;
      |      ^
diversity.cpp:26:13: warning: unused variable 'r' [-Wunused-variable]
   26 |   LL l = 0, r = 0, gi = 1;
      |             ^