求助(全re)

P2249 【深基13.例1】查找

Diary_51 @ 2024-02-18 18:10:38

#include<bits/stdc++.h>
using namespace std;
long long a[1000005];
int main()
{
    long long n,m,q;
    cin>>n>>m;
    for(int i=1;i<=n;i++)
    {
        cin>>q;
        if(a[q]==0)
        {
            a[q]=i;
        }
    }
    for(int i=0;i<m;i++)
    {
        cin>>q;
        if(a[q]!=0)
        {
            cout<<a[q]<<" ";
        }
        else
        {
            cout<<-1<<" ";
        }
    }
    return 0;
}

求调


by danlao @ 2024-02-18 18:36:50

@QWQ_123 你这 O(n\ log \ n) 时间复杂度跟二分有什么区别???


by QWQ_123 @ 2024-02-18 18:37:07

@yaodiguoan so?


by QWQ_123 @ 2024-02-18 18:37:43

@yaodiguoan 我只不过是说可以这么做啊,我没说比二分复杂度更优罢(/jk


by NEKO_Daze @ 2024-02-18 18:38:19

@yaodiguoan 主要是他这种肯定会爆啊喵


by danlao @ 2024-02-18 18:39:01

@QWQ_123 so you don't use these as well binary search.(binary search=二分)


by QWQ_123 @ 2024-02-18 18:40:08

@yaodiguoan Why?


by QWQ_123 @ 2024-02-18 18:40:58

@yaodiguoan 您是 U 宝罢


by NEKO_Daze @ 2024-02-18 18:41:01

@QWQ_123 个人觉得这个桶版的二分估计不太行喵


by danlao @ 2024-02-18 18:42:02

@QWQ_123 Because of the purpose of the problem.


by NEKO_Daze @ 2024-02-18 18:42:05

我看到题的第一反应就是常规的二分加 lower_bound 简化代码。


上一页 | 下一页