Submission #881877

#TimeUsernameProblemLanguageResultExecution timeMemory
881877TAhmed33Diversity (CEOI21_diversity)C++98
0 / 100
2 ms2652 KiB
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize ("Ofast") #pragma GCC target ("popcnt") typedef long long ll; const int MAXN = 3e5 + 25; const int ORIGIN = 3e5; int a[MAXN], n, q; int freq[MAXN]; inline ll sq (ll x) { return (x * (x + 1)) >> 1ll; } int main () { ios::sync_with_stdio(0); cin.tie(0); cin >> n >> q; for (int i = 1; i <= n; i++) cin >> a[i]; for (int g = 1; g <= q; g++) { int l, r; cin >> l >> r; memset(freq, 0, sizeof(freq)); for (int i = l; i <= r; i++) { freq[a[i]]++; } ll cur = 0; for (int i = 1; i <= ORIGIN; i++) { if (freq[i]) cur++; freq[i] += freq[i - 1]; } ll ans = 0; for (int i = 1; i <= ORIGIN; i++) { if (freq[i] - freq[i - 1]) ans += sq(freq[i - 1]) + sq(r - l + 1 - freq[i]); } cout << (cur * sq(r - l + 1)) - ans << '\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...