#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';
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
76 ms |
4088 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
76 ms |
4088 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |