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 <iostream>
#include <algorithm>
using namespace std;
const int nmax = 2e5 + 1;
struct numar {
int val, i;
} ax[nmax];
bool cmp(numar a, numar b) {
return a.val < b.val;
}
int check(int x) {
int cnt = 0;
while(x % 2 == 0) {
cnt ++;
x /= 2;
}
return cnt;
}
int ans[nmax], v[nmax];
int main() {
int n;
cin >> n;
for(int i = 1; i <= n; i ++) {
cin >> v[i];
}
int q;
cin >> q;
for(int i = 1; i <= q; i ++) {
cin >> ax[i].val;
ax[i].i = i;
}
sort(ax + 1, ax + q + 1, cmp);
int curr = 0, ult = 0, an = 1;
for(int i = 1; i <= n; i ++) {
if(an == q + 1) {
break;
}
ult = curr;
curr ++;
ult ++;
int x = check(v[i]);
curr += (1 << x) - 1;
if(ult <= ax[an].val && ax[an].val <= curr) {
ans[ax[an].i] = v[i] / (1 << x);
an ++;
i --;
curr -= (1 << x);
ult --;
}
}
for(int i = 1; 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... |