Submission #964835

#TimeUsernameProblemLanguageResultExecution timeMemory
964835MinaRagy06Diversity (CEOI21_diversity)C++17
0 / 100
1 ms2904 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long const int N = 300'005; int a[N], frq[N]; int main() { ios_base::sync_with_stdio(0), cin.tie(0); int n, q; cin >> n >> q; for (int i = 0; i < n; i++) { cin >> a[i]; frq[a[i]]++; } vector<int> v; for (int i = 0; i < N; i++) { if (frq[i]) { v.push_back(frq[i]); } } n = v.size(); ll ans = 0; for (int i = 0; i < n; i++) { ans += v[i] * (v[i] + 1) / 2; for (int j = i + 1; j < n; j++) { ans += 1ll * v[i] * v[j] * (j - i + 1); } } cout << ans << '\n'; return 0; }
#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...