Submission #538900

#TimeUsernameProblemLanguageResultExecution timeMemory
538900amunduzbaevDiversity (CEOI21_diversity)C++14
0 / 100
1 ms212 KiB
#include "bits/stdc++.h" using namespace std; #define ar array #define int long long #define bug(x) cerr << #x << ' ' << x << '\n'; const int N = 3e5 + 5; int a[N]; signed main(){ ios::sync_with_stdio(0); cin.tie(0); int n, q; cin>>n>>q; for(int i=0;i<n;i++) cin>>a[i]; sort(a, a + n); int tot = 0, res = 0; for(int i=0;i<n;){ int j = i; while(j<n && a[j] == a[i]) j++; tot++; res -= i * (i + 1); //~ cout<<i<<" "<<n - j<<"\n"; res -= (n - j) * (n - j + 1); i = j; } //~ cout<<tot<<" "<<res<<"\n"; res += tot * n * (n + 1); res /= 2; cout<<res<<"\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...