This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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; // pw[l] <= pw[m] <= c <= pw[r]
}else{
r = m - 1; // pw[l] < c < pw[m] <= pw[r]
}
}
cout << ((c > pw[l]) ? a[l + 1] : a[l]) << '\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... |