Submission #993678

#TimeUsernameProblemLanguageResultExecution timeMemory
993678vladiliusDiversity (CEOI21_diversity)C++17
0 / 100
1 ms348 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<int, int>; #define pb push_back #define ff first #define ss second #define ins insert int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, q; cin>>n>>q; vector<int> a(n + 1); for (int i = 1; i <= n; i++){ cin>>a[i]; } sort(a.begin() + 1, a.end()); vector<int> all = {0}; int i = 1; while (i <= n){ int j = i; while (j <= n && a[i] == a[j]){ j++; } all.pb(j - i); i = j; } ll out = 0, pr = 0; for (int i: all) out += (1LL * i * (i + 1)) / 2; n = (int) all.size() - 1; int sum = 0; for (int i = 1; i <= n; i++){ out += 1LL * all[i] * (1LL * i * sum - pr); sum += all[i]; pr += 1LL * (i - 1) * all[i]; } cout<<out<<"\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...