2 solutions

  • 0
    @ 2024-11-17 18:11:35
    #include <bits/stdc++.h>
    using namespace std;
    
    const int N = 200005;
    
    int a[N], b[N], c[N], st[N * 3];
    int n, m, cnt;
    int ans, res;
    map<int, int> s;
    
    int find(int x) { // 对当前的值进行离散化,并返回该值
        if(!s.count(x)) s[x] = ++ cnt;
        return s[x];
    } // 操作是log(n)的
    
    int main() {
        cin >> n;
        for(int i = 1; i <= n; i ++ ) {
            scanf("%d", &a[i]);
            a[i] = find(a[i]);
            st[a[i]] ++ ; // 对当前哈希值存入表中
        }
        cin >> m;
        for(int i = 1; i <= m; i ++ ) scanf("%d", &b[i]);
        for(int i = 1; i <= m; i ++ ) scanf("%d", &c[i]);
        //比较答案
        for(int i = 1; i <= m; i ++ ) {
            int x = find(b[i]);
            if(st[x] > res) ans = i, res = st[x];
            else if(st[x] == res) {
                int y = find(c[i]);
                if(st[y] >= st[find(c[ans])]) ans = i;
            }
        }
        cout << ans << endl;
        return 0;
    }
    

    Information

    ID
    499
    Time
    1000ms
    Memory
    256MiB
    Difficulty
    9
    Tags
    (None)
    # Submissions
    24
    Accepted
    2
    Uploaded By