记录编号 558920 评测结果 AAAAAAAAAAAAAAAAAAAA
题目名称 电影 最终得分 100
用户昵称 Gravataryrtiop 是否通过 通过
代码语言 C++ 运行时间 0.836 s
提交时间 2021-02-03 21:22:01 内存使用 4.31 MiB
显示代码纯文本
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn = 200005;
int a[maxn << 2],c[maxn << 2],res[maxn << 2],pos[maxn << 2];
int vis[maxn << 2];
int n,m,cnt;
int find(int* A,int l,int r,int x) {
    if(A[l] == x)return l;
    if(A[r] == x)return r;
    int mid;
    while(l <= r) {
        mid = l + r >> 1;
        if(A[mid] == x)return mid;
        if(A[mid] < x)l = mid + 1;
        else r = mid - 1;
    }
    if(A[l] == x)return l;
    if(A[r] == x)return r;
}
int main() {
    freopen("cinema.in","r",stdin);
    freopen("cinema.out","w",stdout);
    scanf("%d",&n);
    for(int i = 1;i <= n;++ i) {
        scanf("%d",&a[i]);
        c[i] = a[i];
    }
    scanf("%d",&m);
    for(int i = 1;i <= (m << 1);++ i) {
        scanf("%d",&a[i + n]);                 
        c[i + n] = a[i + n];
    }
    sort(c + 1 , c + 1 + n + (m << 1));
    for(int i = 1;i <= n + (m << 1);++ i) {
        if(c[i] != c[i - 1]) {
            res[++ cnt] = c[i];
        }
    }
//    printf("res : ");
//    for(int i = 1;i <= cnt;++ i) {
//        printf("%d ",res[i]);
//    }
//    putchar('\n');                
    for(int i = 1;i <= n;++ i) {
        pos[i] = find(res , 1 , cnt , a[i]);
        ++ vis[pos[i]];
//        printf("i : %d        pos[%d] : %d\n",i,i,pos[i]);
    }                                                                
    for(int i = n + 1;i <= n + (m << 1);++ i) {
        pos[i] = find(res , 1 , cnt , a[i]);
//        printf("i : %d        pos[%d] : %d\n",i,i,pos[i]);
    }                         
    int mx = 1;
    for(int i = 1;i <= m;++ i) {
        if(vis[pos[i + n]] > vis[pos[mx + n]]) {
        	mx = i;
        	continue ;
        }
        else if(vis[pos[i + n]] == vis[pos[mx + n]]&&(vis[pos[i + n + m]] >= vis[pos[mx + n + m]])) {
        	mx = i;
        	continue ;
        }
    }
    printf("%d",mx);
    fclose(stdin);
    fclose(stdout);
    return 0;
}