Luo Gu CF670C Cinema

Luo Gu CF670C Cinema

Description

  • In an important Ke scientists have organized n different countries participated in the international conference in Moscow, each Ke scientists are only one language. For convenience, we specify a language to describe a number from 1 to 10 ^ 9.
    In the evening after the meeting, Ke scientists decided to go to the movies. They went to a movie theater there m, every field there are two different numbers, representing the voice of the language and subtitle language. If a scientist can understand Ke dub, he will be very pleasant; if we can read the subtitles, he would be more satisfied. If both can not read could not understand, he will be very angry.
    Ke scientists decided to go with a movie, you have to help them choose a movie, so that people under the most pleasant premise, the most satisfied with the people.

Input

  • Input format: The first line of an integer n (1≤n≤200000) Ke represents the number of scientists.
    The second line n integers a1, a2, ..., an ( 1≤ai≤109) represents the language Ke scientists will.
    The third line represents an integer 1≤m≤200000 the movie.
    The fourth row m integers b1, b2, ..., bn ( 1≤bj≤109) represents sound of the movie with the language.
    The fifth line m integers c1, c2, ..., cn ( 1≤cj≤109) representation language movie with subtitles.

Output

  • Output Format: An integer representation arrangements which a movie. If there are multiple cases, choose more satisfied with the program output.

Sample Input

3
2 3 2
2
3 2
2 3

Sample Output

2

answer:

  • Discrete.
  • Although the film can number in the range of int expressed, but impossible to open a large array INT_MAX. So we continue to observe the subject and found that the data will appear in a maximum of m * 2 + n languages, 60w is the largest species, the array can be opened. Then discrete, direct buckets to count the number of people in each language, and then select the title is intended to meet the requirements of the film.
#include <iostream>
#include <cstdio>
#include <algorithm>
#define N 400005
using namespace std;

struct Obj {int x, y, z;} obj[N];
int n, m, cnt;
int a[N], b[N * 3], c[N * 3], d[N * 3];

int read()
{
    int x = 0; char c = getchar();
    while(c < '0' || c > '9') c = getchar();
    while(c >= '0' && c <= '9') {x = x * 10 + c - '0'; c = getchar();}
    return x;
}

int find(int x) {
    return lower_bound(b + 1, b + 1 + cnt, x) - b;
}

bool cmp(Obj u, Obj v)
{
    if(u.x == v.x)
    {
        if(u.y == v.y) return u.z < v.z;
        else return u.y > v.y;
    }
    else return u.x > v.x;
}

int main()
{
    cin >> n;
    for(int i = 1; i <= n; i++) a[i] = read(), b[++cnt] = a[i];
    cin >> m;
    for(int i = 1; i <= m; i++) obj[i].x = read(), b[++cnt] = obj[i].x, obj[i].z = i;
    for(int i = 1; i <= m; i++) obj[i].y = read(), b[++cnt] = obj[i].y;
    sort(b + 1, b + 1 + cnt);
    cnt = unique(b + 1, b + 1 + cnt) - b - 1;
    for(int i = 1; i <= n; i++)
        c[find(a[i])]++, d[find(a[i])]++;
    for(int i = 1; i <= m; i++) obj[i].x = c[find(obj[i].x)], obj[i].y = d[find(obj[i].y)];
    sort(obj + 1, obj + 1 + m, cmp);
    cout << obj[1].z;
    return 0;
}

Guess you like

Origin www.cnblogs.com/BigYellowDog/p/11270532.html