답안 #487235

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
487235 2021-11-14T20:51:28 Z nickmet2004 Diversity (CEOI21_diversity) C++11
0 / 100
1 ms 204 KB
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N = 3e5 + 5;
int n , q , a[N];
int P[N] , p[N];
 main (){
   cin >> n >> q;
   for(int i = 1; i <= n; ++i)cin >> a[i];


   sort(a + 1 , a + n + 1);
   vector<int> v{0};
   int k = 1;
   for(int i = 1; i <= n; ++i){
    if(a[i] == a[i + 1])k++;
    else v.emplace_back(k),k=1;
   }
   //for(int x : v)cout << x << " ";cout << endl;
   for(int i =1; i < v.size(); ++i){
    p[i] = p[i - 1] + v[i];
    P[i] = P[i - 1] + v[i] * i;
    //cout << P[i] << " ";
   }
   int sz = v.size() - 1,ans=0;
   for(int i =1; i < v.size(); ++i){
      int x = v[i];
      //cout << x << " ";
      //cout << P[sz] - P[i] - (i - 1) * p[sz] << "s"<<endl;
      ans += x * x - x*(x - 1)/2 +  x * ((P[sz] - P[i]) - (i - 1) * (p[sz] - p[i]));
   }
    cout << ans;
}

Compilation message

diversity.cpp:7:2: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
    7 |  main (){
      |  ^~~~
diversity.cpp: In function 'int main()':
diversity.cpp:20:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |    for(int i =1; i < v.size(); ++i){
      |                  ~~^~~~~~~~~~
diversity.cpp:26:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |    for(int i =1; i < v.size(); ++i){
      |                  ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Incorrect 0 ms 204 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Incorrect 0 ms 204 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Incorrect 0 ms 204 KB Output isn't correct
4 Halted 0 ms 0 KB -