답안 #718153

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
718153 2023-04-03T12:59:46 Z mychecksedad Diversity (CEOI21_diversity) C++17
0 / 100
5 ms 1492 KB
/* Author : Mychecksdead */
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define MOD (1000000000+7)
#define MOD1 (998244353)
#define PI 3.1415926535
#define pb push_back
#define all(x) x.begin(), x.end()
const int N = 1e6+100, M = 1e5+10, K = 20;


int n, q, a[N];
vector<int> c(300005);
ll pref[N];
void solve(){
  cin >> n >> q;
  for(int i = 0; i < n; ++i){
    cin >> a[i];
    c[a[i]]++;
  }

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

  sort(all(c));

  deque<ll> Q; 

  bool b = 1;

  for(int i = 0; i <= 300004; ++i){
    if(c[i] > 0){
      if(b)
        Q.push_front(c[i]);
      else
        Q.push_back(c[i]);
      b ^= 1;
    }
  }


  ll ans = 0;
  pref[0] = 0;
  ll m = Q.size();
  for(int i = 0; i < m; ++i) pref[i + 1] = pref[i] + Q[i];
  for(int i = 0; i < m; ++i){
    ans += (pref[m] - pref[i + 1]) * (pref[i]) + (pref[i]) * (Q[i]) + (Q[i]) * (pref[m] - pref[i + 1]) + (Q[i] + 1) * Q[i] / 2;
  }
  cout << ans;
}


int main(){
  cin.tie(0); ios::sync_with_stdio(0);
  int T = 1, aa;
  // cin >> T;aa=T;
  while(T--){
    // cout << "Case #" << aa-T << ": ";
    solve();
    cout << '\n';
  }
  return 0;
 
}

Compilation message

diversity.cpp: In function 'int main()':
diversity.cpp:56:14: warning: unused variable 'aa' [-Wunused-variable]
   56 |   int T = 1, aa;
      |              ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 1492 KB Output is correct
2 Correct 5 ms 1492 KB Output is correct
3 Incorrect 5 ms 1492 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 1492 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 1492 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 1492 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 1492 KB Output is correct
2 Correct 5 ms 1492 KB Output is correct
3 Incorrect 5 ms 1492 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 1492 KB Output is correct
2 Correct 5 ms 1492 KB Output is correct
3 Incorrect 5 ms 1492 KB Output isn't correct
4 Halted 0 ms 0 KB -