用桶的思想真的无法全部AC吗?看来确实是不行。。

P2249 【深基13.例1】查找

SocialPanda @ 2023-02-08 01:24:59

#include <iostream>
#include <malloc.h>
int n;
int m;
int j;
int k;
int* num = (int*)malloc(1000000001 * sizeof(int));
int* psi = (int*)malloc(1000000001 * sizeof(int));
using namespace std;
int main()
{
    scanf("%d %d", &n, &m);
    for (int i = 1; i <= n; i++)
    {
        scanf("%d", &j);
        num[j]++;
        if (num[j] == 1)
        {
            psi[j] = i;
        }
    }
    for (int i = 1; i <= m; i++)
    {
        cin >> k;
        if (num[k] == 0)
        {
            printf("-1 ");
            continue;
        }
        printf("%d ", psi[k]);
    }
    return 0;
}

by SocialPanda @ 2023-02-08 01:26:23

最后一个测试点不是RE就是MLE... 我还是去学习其他方法吧...


by Coffins @ 2023-02-08 07:12:10

@SocialPanda 1e9的话数组会炸掉


by H_Kaguya @ 2023-02-08 07:33:03

map 就行了。


by mashduihca @ 2023-02-08 08:41:17

算算内存


by Tx1234567 @ 2023-02-11 13:51:24

mle70pts


|