#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, q;
cin >> n >> q;
vector<int> s(n);
for(int i=0; i<n; i++){
cin >> s[i];
}
map<int,int> cnt;
for(int i=0; i<n; i++){
cnt[s[i]]++;
}
for(int i=0; i<q; i++){
int a, b;
cin >> a >> b;
}
vector<pair<int,int> > sorted;
for(auto e: cnt){
sorted.push_back({e.second, e.first});
}
sort(sorted.begin(), sorted.end());
vector<pair<int,int> > res(cnt.size());
int l=0; int r=cnt.size()-1; bool left=true;
for(auto e: sorted){
int x=e.second; int anz=e.first;
if(left){
res[l]={x, anz};
l++;
left=false;
}
else{
res[r]={x, anz};
r--;
left=true;
}
}
vector<int> neu(n);
int i=0;
for(auto e: cnt){
int x=e.first;
int anz=e.second;
for(int j=0; j<anz; j++, i++){
neu[i]=x;
}
}
int ans=1;
int last=1;
for(int i=1; i<n; i++){
if(neu[i]==neu[i-1]){
ans+=last+1;
last++;
}
else{
ans+=last+i+1;
last=last+i+1;
}
}
cout << ans << "\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
244 KB |
Output is correct |
3 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
244 KB |
Output is correct |
3 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
244 KB |
Output is correct |
3 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |