제출 #994225

#제출 시각아이디문제언어결과실행 시간메모리
994225faqinyeagerIntercastellar (JOI22_ho_t1)C++17
100 / 100
366 ms9300 KiB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

vector<ll> a, pw;

int main(){
    int n;
    cin >> n;
    a.resize(n), pw.resize(n, 1);
    for(int i = 0; i < n; i++){
        cin >> a[i];
        while(a[i] % 2 == 0){
            a[i] /= 2;
            pw[i] *= 2;
        }
    }

    for(int i = 1; i < n; i++) pw[i] += pw[i - 1];
    //for(int i = 0; i < n; i++) cout << a[i] << ' '; cout << '\n';
    //for(int i = 0; i < n; i++) cout << pw[i] << ' '; cout << "\n\n";

    int Q;
    cin >> Q;
    while(Q--){
        ll c;
        cin >> c;
        int l = 0, r = n - 1;
        while(r - l > 1){
            int m = (l + r) / 2;
            if(pw[m] < c){
                l = m + 1; // pw[l] <= pw[m] <= c <= pw[r] 
            }else{
                r = m; // pw[l] < c < pw[m] <= pw[r]
            }
        }
        cout << ((c > pw[l]) ? a[l + 1] : a[l]) << '\n';
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...