# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
865565 | Rifal | Diversity (CEOI21_diversity) | C++14 | 1 ms | 464 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#include <fstream>
//#define endl '\n'
#define mod 1000000007
#define INF 9000000000000000
using namespace std;
//ofstream fout("intel.out");
//ifstream fin("intel.in");
const int Max = 3e5 + 5;
int cnt[Max];
int main()
{
ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);
int n, q; cin >> n >> q;
long long sum = 0; long long dp[n+1] = {}; long long arr[n];
for(int i = 1; i <= n; i++) dp[i] = 1;
pair<long long,long long> mn1 = {INF,0}, mn2 = {INF,0};
for(int i = 0; i < n; i++) {
cin >> arr[i];
cnt[arr[i]]++;
}
for(int i = 1; i < Max; i++) {
if(cnt[i] != 0) {
if(mn1.first > cnt[i]) {
mn2.first = mn1.first;
mn2.second = mn1.second;
mn1.first = cnt[i];
mn1.second = i;
}
else if(mn2.first > cnt[i]) {
mn2.first = cnt[i];
mn2.second = i;
}
}
}
vector<int> v;
while(cnt[mn1.second]--) {
v.push_back(mn1.second);
}
for(int i = 1; i < Max; i++) {
if(i == mn1.second || i == mn2.second) continue;
if(cnt[i] != 0) {
while(cnt[i]--) {
v.push_back(i);
}
}
}
while(cnt[mn2.second]--) {
v.push_back(mn2.second);
}
if(q == 1) {
int l, r; cin >> l >> r;
sum += dp[1];
for(long long i = 1; i < v.size(); i++) {
if(v[i] != v[i-1]) {
dp[i+1] += i;
}
dp[i+1] += dp[i];
sum += dp[i+1];
}
cout << sum << endl;
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |