#include <iostream>
#include <cmath>
using namespace std;
int main() {
int n;
cin >> n;
int A[n]; //len
unsigned long long total_castella[n];
for (int i=0; i<n; i++) {
cin >> A[i];
total_castella[i] = (A[i] % 2 == 0) ? 0 : 1;
if (A[i] >= 8 && pow(2,log2(A[i])) == A[i]) total_castella[i] = 2;
int tmp = A[i];
while (tmp%2 == 0) {
tmp/=2;
total_castella[i]+=2;
}
A[i] = tmp;
if (i>0) total_castella[i]+=total_castella[i-1];
}
int Q;
cin >> Q;
for (int i=0; i<Q; i++) {
unsigned long long x;
cin >> x;
int left = 0;
int right = n-1;
int ans = 0;
while (left <= right) {
int mid = left+(right-left)/2;
if (total_castella[mid] < x) {
left = mid+1;
}
else {
if (mid != 0 && total_castella[mid-1] < x) ans = mid;
else if (total_castella[mid-1] == x) ans = mid-1;
right = mid-1;
}
}
cout << A[ans] << "\n";
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |