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;
int n,m;
struct cake{
int len;
long long l,r;
}a[200005];
int main(){
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cin>>n;
a[0].r=0;
for (int i=1;i<=n;i++){
cin>>a[i].len;
long long cnt=1;
while (a[i].len%2==0){
a[i].len/=2;
cnt*=2;
}
a[i].l=a[i-1].r+1;
a[i].r=a[i-1].r+cnt;
}
cin>>m;
while (m--){
long long t,ptl=1,ptr=n,mid;
cin>>t;
while (ptl<=ptr){
mid=(ptl+ptr)/2;
if (a[mid].l<=t && a[mid].r>=t){
cout<<a[mid].len<<"\n";
break;
}
else if (a[mid].l>t) ptr=mid-1;
else ptl=mid+1;
}
}
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... |