#include <bits/stdc++.h>
// Author: Kazuki_Will_Win_VOI_8703
#define fi first
#define se second
#define pii pair<int, int>
#define int long long
#define all(a) a.begin(), a.end()
using namespace std;
const int mn = 5e5 + 5, bm = (1 << 11) + 1, mod = 1e9 + 7, offset = 5e4, B = 320 + 5;
const int inf = 1e18, base = 311;
int n, bit[mn], a[mn], f[mn];
void add(int u, int val){
while(u <= n){
bit[u] += val;
u += (u & -u);
}
}
int get(int u){
int res = 0;
while(u){
res += bit[u];
u -= (u & -u);
}
return res;
}
int walk(int val){
int l = 1, r = n, ans = -1;
while(l <= r){
int mid = (l + r) >> 1;
if(get(mid) >= val){
r = mid - 1;
ans = mid;
}
else l = mid + 1;
}
return ans;
}
void solve(){
cin >> n;
for(int i = 1; i <= n; i++){
cin >> a[i];
int cnt = 1;
while(a[i] % 2 == 0){
cnt *= 2;
a[i] /= 2;
}
add(i, cnt);
}
int q; cin >> q;
while(q--){
int pos; cin >> pos;
cout << a[walk(pos)] << '\n';
}
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t = 1;
// cin >> t;
while(t --){
solve();
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |