3 条题解

  • -1
    @ 2024-11-22 0:05:37

    不如yxy

    
    #include <bits/stdc++.h>
    #define int long long
    #define pow_of_two(n) (n & -n == n) 
    using namespace std;
    #define lowbit(x) (x) & (-x)
    // const int N = 1e6 + 10;
    int n , q , ans;
    vector<int> a;
    
    int search2(int x)
    {
        int l = 0 , r = n - 1 ;
        while (l < r)
        {
            int mid = l + r + 1 >> 1;
            if (a[mid] <= x) l = mid;
            else r = mid - 1;
    
        }
    
        return l;
    }
    
    
    int search1(int x)
    {
        int l = 0 , r = n - 1 ;
        while (l < r)
        {
            int mid = l + r >> 1;
            if (a[mid] >= x) r = mid;
            else l = mid + 1;
    
        }
    
        return l;
    }
    
    inline void solve() 
    {   
        cin >> n >> q;
        for (int i = 1 , temp ; i <= n ; i ++ ) cin >> temp , a.push_back(temp);
    
        while (q -- ) 
        {
            int x;
            cin >> x;
            int ans = search1(x);
            if (a[ans]!= x) cout << "No answer" << endl;
            else
            {
                cout << ans << " ";
                ans = search2(x);
                cout << ans << endl;
            }   
        }    
    
        return ;
    }
    
    
    signed main()
    {
        ios::sync_with_stdio(false) , cin.tie(0) , cout.tie(0);
        solve();
        return 0;
    }
    
    

    信息

    ID
    80
    时间
    1000ms
    内存
    256MiB
    难度
    8
    标签
    递交数
    18
    已通过
    5
    上传者