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
#define ll long long
using namespace std;
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int N; cin >> N;
vector<pair<ll,ll>> vec;
for(int i = 0;i<N;++i){
ll x; cin >> x;
ll cur = 1;
while(x % cur == 0){
cur *= 2;
}
cur /= 2; x /= cur;
vec.push_back({cur,x});
}
int Q; cin >> Q;
vector<pair<ll,int>> queries; //value, index
for(int i = 0;i<Q;++i){
ll x; cin >> x;
queries.push_back({x,i});
}
sort(queries.begin(),queries.end());
vector<int> ans(Q,0);
int j = 0; ll cnt = 0ll;
for(int i = 0;i<Q;++i){
while(j < N && cnt+vec[j].f < queries[i].f){
cnt += vec[j].f;
++j;
}
ans[queries[i].s] = vec[j].s;
}
for(int i = 0;i<Q;++i){
cout << ans[i] << "\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... |