제출 #1267669

#제출 시각아이디문제언어결과실행 시간메모리
1267669gustavo_dIntercastellar (JOI22_ho_t1)C++20
100 / 100
55 ms4676 KiB
#include <bits/stdc++.h>
using namespace std;

const int MAXN = 2e5;

typedef long long ll;

int a[MAXN];
ll pf[MAXN];

int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);

    int n; cin >> n;
    for (int i=0; i<n; i++) {
        cin >> a[i];
        int pow2 = 1;
        while (!(a[i] & 1)) {
            a[i] /= 2;
            pow2 *= 2;
        }
        pf[i] = (i == 0 ? 0 : pf[i-1]) + pow2;
    }

    int qs; cin >> qs;
    for (int q=0; q<qs; q++) {
        ll x; cin >> x;
        int l = 0, r = n-1; int ans = -1;
        while (l <= r) {
            int mid = (l + r) / 2;
            if (pf[mid] >= x) {
                ans = mid;
                r = mid-1;
            } else {
                l = mid+1;
            }
        }
        cout << a[ans] << '\n';
    }

    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...