前缀和一下,就好了
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
const int N=1e5+99;
int a[N],odd[N],even[N];
struct cmp
{
bool operator () (int A,int B)
{
return odd[A]<odd[B];
}
};
struct cmp1
{
bool operator () (int A,int B)
{
return even[A]<even[B];
}
};
priority_queue<int,vector<int> ,cmp>qo;
priority_queue<int,vector<int> ,cmp1>qe;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin>>n;
for(int i=1;i<=n;++i)
{
cin>>a[i];
if(i&1)
{
odd[a[i]]++;
}
else
{
even[a[i]]++;
}
}
for(int i=1;i<=N;++i)
{
qo.push(i);
qe.push(i);
}
if(qo.top()!=qe.top())
{
cout<<n-odd[qo.top()]-even[qe.top()];
}
else
{
int t1=odd[qo.top()];qo.pop();
int t2=even[qe.top()];
qe.pop();
cout<<n-max(t2+odd[qo.top()],t1+even[qe.top()]);
}
}
标签:even,int,题解,long,ARC,103,odd
From: https://www.cnblogs.com/yhz2006-OI/p/16889440.html