离散化
通过时间957mm
最漂亮的离散化代码
C++ 代码
#include<bits/stdc++.h>
using namespace std;
const int N = 200010;
int n,m,alls[3*N],cnt[3*N],idx,a[N],b[N],c[N];
void unique() {
int j=0;
for(int i=0;i<idx;i++)
if(!i||alls[i]!=alls[i-1])alls[j++] = alls[i];
idx = j;
}
int find(int x) {
int L = 0,R = idx-1;
while(L<=R) {
int mid = L + (R-L>>1);
if(alls[mid]>=x) R = mid-1;
else L = mid+1;
}
return L;
}
int main() {
ios::sync_with_stdio(false),cin.tie(0);
cin>>n;
for(int i=0;i<n;i++)cin>>a[i],alls[idx++] = a[i];
cin>>m;
for(int i=0;i<m;i++)cin>>b[i],alls[idx++]=b[i];
for(int i=0;i<m;i++)cin>>c[i],alls[idx++]=c[i];
sort(alls,alls+idx),unique();
for(int i=0;i<n;i++) cnt[find(a[i])]++;
int index = 0;
for(int i=1;i<m;i++) {
int cur = cnt[find(b[i])],max = cnt[find(b[index])];
if(cur>max || (cur==max&&cnt[find(c[i])]>cnt[find(c[index])])) index = i;
}
cout<<index+1;
}