Submission #827325

#TimeUsernameProblemLanguageResultExecution timeMemory
827325BERNARB01Diversity (CEOI21_diversity)C++17
0 / 100
1 ms1492 KiB
/** * author: BERNARD B.01 **/ #include <bits/stdc++.h> using namespace std; #ifdef B01 #include "deb.h" #else #define deb(...) #endif int main() { ios::sync_with_stdio(false); cin.tie(0); int n, q; cin >> n >> q; vector<int> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } const int N = (int) 3e5 + 1; vector<int> cnt(N); for (int i = 0; i < n; i++) { cnt[a[i]]++; } vector<pair<int, int>> freqs; for (int i = 0; i < N; i++) { if (cnt[i] > 0) { freqs.emplace_back(cnt[i], i); } } sort(freqs.rbegin(), freqs.rend()); deque<int> d; for (int i = 0; i < (int) freqs.size(); i++) { if (i & 1) { d.push_front(freqs[i].second); } else { d.push_back(freqs[i].first); } } vector<int> pos(n); for (int i = 0; i < (int) freqs.size(); i++) { pos[freqs[i].second] = i; } sort(a.begin(), a.end(), [&](int i, int j) { return pos[i] < pos[j]; }); long long ans = 0; for (int i = 0; i < n; i++) { if (i == 0 || a[i] != a[i - 1]) { ans += (long long) (i + 1) * (n - i); } else { ans += (n - i); } } while (q--) { int l, r; cin >> l >> r; --l; --r; 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...