제출 #824967

#제출 시각아이디문제언어결과실행 시간메모리
824967phoenixIntercastellar (JOI22_ho_t1)C++17
100 / 100
73 ms10072 KiB
#include<bits/stdc++.h>

using namespace std;
using ll = long long;



int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    int n;
    cin >> n;
    int a[n];
    vector<pair<int, int>> v;
    for(int i = 0; i < n; i++) {
        cin >> a[i];
        int x = a[i], k = 1;
        while(x % 2 == 0) {
            x /= 2;
            k *= 2;
        }
        v.push_back({x, k});
    } 
    ll sm[n];
    for(int i = 0; i < n; i++) 
        sm[i] = v[i].second + (i ? sm[i - 1] : 0);
    
    int q;
    cin >> q;
    while(q--) {
        ll x;
        cin >> x; 
        int lb = -1, rb = n;
        while(rb - lb > 1) {
            int mid = (lb + rb) / 2;
            if(sm[mid] < x) lb = mid;
            else rb = mid;
        }     
        if(rb == n) cout << -1;
        else cout << v[rb].first;
        cout << '\n';
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...