您的位置:首页 > 其它

Cinema CodeForces - 670C (map,一维坐标离散化,排序)

2017-11-15 21:02 375 查看


Cinema

 CodeForces - 670C 

Moscow is hosting a major international conference, which is attended by nscientists from different countries. Each of the scientists knows exactly one language. For convenience, we enumerate all languages of the world
with integers from 1 to 109.

In the evening after the conference, all n scientists decided to go to the cinema. There are m movies in the cinema they came to. Each of the movies is characterized by two distinct numbers —
the index of audio language and the index of subtitles language. The scientist, who came to the movie, will be very pleased if he knows the audio language of the movie, will be almost satisfied if
he knows the language of subtitles and will be not satisfied if he does not know neither one nor the other (note that the audio language and the subtitles language for each movie are always different).

Scientists decided to go together to the same movie. You have to help them choose the movie, such that the number of very pleased scientists is maximum possible. If there are several such movies, select among them one that will maximize the number of almost
satisfied scientists.

Input

The first line of the input contains a positive integer n (1 ≤ n ≤ 200 000) — the number of scientists.

The second line contains n positive integers a1, a2, ..., an (1 ≤ ai ≤ 109),
where aiis the index of a language, which the i-th scientist knows.

The third line contains a positive integer m (1 ≤ m ≤ 200 000) — the number of movies in the cinema.

The fourth line contains m positive integers b1, b2, ..., bm (1 ≤ bj ≤ 109),
where bjis the index of the audio language of the j-th movie.

The fifth line contains m positive integers c1, c2, ..., cm (1 ≤ cj ≤ 109),
where cj is the index of subtitles language of the j-th movie.

It is guaranteed that audio languages and subtitles language are different for each movie, that is bj ≠ cj.

Output

Print the single integer — the index of a movie to which scientists should go. After viewing this movie the number of very pleased scientists should be maximum possible. If in the cinema there are several such movies, you need to choose among them one, after
viewing which there will be the maximum possible number of almost satisfied scientists.

If there are several possible answers print any of them.

Example

Input
3
2 3 2
2
3 2
2 3


Output
2


Input
6
6 3 1 1 3 7
5
1 2 3 4 5
2 3 4 5 1


Output
1


Note

In the first sample, scientists must go to the movie with the index 2, as in such case the 1-th and the 3-rd scientists will be very pleased and the 2-nd
scientist will be almost satisfied.

In the second test case scientists can go either to the movie with the index 1 or the index 3. After viewing any of these movies exactly two scientists will
be very pleased and all the others will be not satisfied.

code:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>
using namespace std;
int num[200002];//用于储存每种语言的个数(经过离散化)
struct node{//电影结构体
int pos;//记录电影的标号
int lan,sub;//电影的声音语言和字幕语言
}movie[200002];
//一种较快的方法是用数组下标作为语言的代表序号,每次输入一个语言序号这个数组元素++,以此记录每种语言出现的个数
//但是由于语言的标号最大会达到1e9会超数组,所以可以用map将语言的序号离散化,说白了就是使整体序号变小,减少空间浪费
map<int,int>mp;//利用map离散化语言的编号
int a[200002];//记录语言
bool cmp(node a,node b){
if(num[a.lan] == num[b.lan]){//如果声音语言相同,按照字幕语言多的排序
return num[a.sub] > num[b.sub];
}
return num[a.lan] > num[b.lan];//按声音语言多的排序
}
int main(){
int n;
scanf("%d",&n);
int i,j;
int cnt = 1;//用于坐标离散化的标记量,使原来分散的语言连续记录,避免空间浪费
for(i = 1; i <= n; i++){
int x;
scanf("%d",&x);
if(!mp.count(x)){//如果这个语言第一次出现
mp[x] = cnt;//这个语言映射一个连续的数字
a[i] = cnt++;//语言也相应储存离散化的坐标
}
else{//如果这个语言出现过,储存map映射的数字
a[i] = mp[x];
}
}
memset(num,0,sizeof(num));
for(i = 1; i <= n; i++){
num[a[i]]++;//统计每种语言出现的次数,这样用数组下标统计就完全可以储存下了
}
int m;
scanf("%d",&m);
for(i = 1; i <= m; i++){
int lan;
scanf("%d",&lan);
movie[i].pos = i;
movie[i].lan = mp[lan];//储存电影的标号和声音语言所映射的数字
}
for(i = 1; i <= m; i++){
int sub;
scanf("%d",&sub);
movie[i].sub = mp[sub];//同理储存的是语言序号所映射的数字
}
sort(movie+1,movie+1+m,cmp);//根据让最多的人very开心其次让最多人满意的原则排序
printf("%d\n",movie[1].pos);//输出排在第一个电影的序号
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: