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;
#define ll long long
#define fi first
#define se second
#define endl "\n"
#define pii pair<ll,ll>
#define pb push_back
#define vi vector<ll>
#define pque priority_queue
#define pqueg priority_queue<ll,vector<ll>,greater<ll>>
#define que queue<ll>
#define FOR(m,i,n) for(int i=(m); i<=(n); i++)
#define FORM(m,i,n) for(int i=(m); i>=(n); i--)
#define all(v) sort(v.begin(),v.end())
ll n,q,x,freq;
ll l,r,m,ans;
ll pref[200200];
ll a[200200];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n;
FOR(1,i,n) {
cin >> a[i];
freq = 1;
while(a[i] % 2 == 0) {
a[i] /= 2;
freq *= 2;
}
pref[i] = pref[i-1] + freq;
}
cin >> q;
while(q--) {
cin >> x;
l = 1;
r = n;
while(l <= r) {
m = (l+r)/2;
if(pref[m] >= x) {
ans = a[m];
r = m - 1;
}
else {
l = m + 1;
}
}
cout << ans << 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... |