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>
#define f first
#define s second
using namespace std;
long long n,i,j,si[200005],cnt[200005],q,tmp;
long long a[200005];
long long f(long long x){
if (x==1) return si[1];
long long l=1; long long r=n;
long long ans=0;
while (l<=r){
long long mid=(l+r)/2;
if (cnt[mid]<x){
l=mid+1;
}
else {
ans=mid;
r=mid-1;
}
}
return si[ans];
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cin>>n;
for (i=1;i<=n;i++) {
cin>>a[i];
cnt[i]=1;
si[i]=a[i];
while (si[i]%2==0){
si[i]/=2;
cnt[i]*=2;
}
cnt[i]+=cnt[i-1];
}
cin>>q;
while (q--){
cin>>tmp;
cout<<f(tmp)<<endl;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |