/*#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <bitset>
#include <numeric>
using namespace std;
#define ll long long
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n; cin>>n;
vector<ll> arr(n);
vector<ll> finalPosOfSeg(n);
ll currPos = 0;
for(int i = 0; i < n; i++){
cin>>arr[i];
ll cnt = 0;
while(arr[i]%2!=1){
cnt++;
arr[i]/=2;
}
currPos+=pow(2, cnt);
finalPosOfSeg[i] = currPos-1;
}
int q; cin>>q;
int l = 0;
while(q--){
ll x; cin>>x; x--;
while(finalPosOfSeg[l] < x){
l++;
}
cout<<arr[l]<<"\n";
}
}*/
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
#define ll long long
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
vector<ll> arr(n);
vector<ll> finalPosOfSeg(n);
ll currPos = 0;
for (int i = 0; i < n; i++) {
cin >> arr[i];
ll cnt = 0;
while (arr[i] % 2 == 0) { // keep dividing until odd
cnt++;
arr[i] /= 2;
}
currPos += (1LL << cnt); // use bit shift instead of pow
finalPosOfSeg[i] = currPos - 1;
}
int q;
cin >> q;
vector<int> xs(q);
for (int i = 0; i < q; i++) {
cin >> xs[i];
}
int l = 0;
for (int i = 0; i < q; i++) {
int x = xs[i] - 1; // convert to 0-index
while (finalPosOfSeg[l] < x) {
l++;
}
cout << arr[l] << "\n";
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |