QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#578185 | #9313. Make Max | aikongsky | RE | 0ms | 0kb | C++14 | 888b | 2024-09-20 17:13:21 | 2024-09-20 17:13:21 |
answer
#include<bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
typedef long long ll;
int a[N];
vector<int>cnt;
int n,t;
void solve()
{
// memset(cnt,0,sizeof(cnt));
cnt.clear();
ll sum = 0;
cin>>n;
for(int i = 1;i <= n;i++)
{
scanf("%d",&a[i]);
}
sort(a+1,a+1+n);
// cout<<endl;
// cout<<"下面是答案:"<<endl;
if(n == 2) {
if(a[1] != a[2]) cout<<"1"<<endl;
else cout<<"0"<<endl;
}
else {
int max = a[n];
for(int i = 1;i < n;i++)
{
cnt[a[i]]++;
}
for(int i = 1;i < n - cnt[max];i++)
{
// cout<<"cnt["<<a[i]<<"] = "<<cnt[a[i]]<<endl;
if(a[i] != a[i-1])
{
cnt[a[i]] = cnt[a[i]] + cnt[a[i-1]];
// cout<<"cnt["<<a[i]<<"] = "<<cnt[a[i]]<<endl;
sum += cnt[a[i]];
}
}
cout<<sum<<endl;
}
// cout<<endl;
}
int main()
{
cin>>t;
while(t--)
{
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Runtime Error
input:
4 2 1 2 2 2 2 7 1 1 1 2 2 2 2 3 1 2 3
output:
1 0