题目链接:https://codeforces.com/problemset/problem/670/C
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
const int N = 200010;
// n个科学家,数组a存储每个科学家使用的语言
int n, a[N];
// m场电影,数组b和数组c分别存储每场电影的配音语言和字幕语言
int m, b[N], c[N];
// tot和数组lang存储涉及到的所有语言,len存储去重后的语言种数
int lang[N * 3], tot, len;
// 数组p存储每种语言被多少个科学家使用
int p[N * 3];
int get(int x)
{
return lower_bound(lang + 1, lang + len + 1, x) - lang;
}
int main()
{
scanf("%d", &n);
for (int i = 1; i <= n; i++)
{
scanf("%d", &a[i]);
lang[++tot] = a[i];
}
scanf("%d", &m);
for (int i = 1; i <= m; i++)
{
scanf("%d", &b[i]);
lang[++tot] = b[i];
}
for (int i = 1; i <= m; i++)
{
scanf("%d", &c[i]);
lang[++tot] = c[i];
}
// 离散化
sort(lang + 1, lang + tot + 1);
len = unique(lang + 1, lang + tot + 1) - (lang + 1);
for (int i = 1; i <= n; i++)
{
p[get(a[i])]++;
}
int ans = -1, maxb = -1, maxc = -1;
for (int i = 1; i <= m; i++)
{
int bn = p[get(b[i])]; // 能听懂该场电影配音(愉悦)的科学家个数
int cn = p[get(c[i])]; // 能看懂该场电影字幕(满意)的科学家个数
if(bn > maxb || (bn == maxb && cn > maxc))
{
ans = i;
maxb = bn;
maxc = cn;
}
}
printf("%d\n", ans);
return 0;
}