#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
int main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
int N; cin >> N;
vector<int> A(N);
for (int i = 0; i < N; ++i) {
cin >> A[i];
}
function<int(int)> rec = [&](int x) {
if (x & 1) {
return 1;
}
return rec(x / 2) + rec(x / 2);
};
vector<array<int, 2>> B;
for (int i = 0; i < N; ++i) {
int x = A[i];
while (x % 2 == 0) {
x /= 2;
}
B.push_back({x, rec(A[i])});
}
for (int i = 1; i < N; ++i) {
B[i][1] += B[i - 1][1];
}
int Q; cin >> Q;
while (Q--) {
long long X; cin >> X;
int L = 0, R = N - 1, res = -1;
while (L <= R) {
int md = (L + R) / 2;
if (B[md][1] >= X) {
res = md;
R = md - 1;
} else {
L = md + 1;
}
}
cout << B[res][0] << "\n";
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
17 ms |
4012 KB |
Output is correct |
4 |
Correct |
22 ms |
2400 KB |
Output is correct |
5 |
Correct |
39 ms |
4804 KB |
Output is correct |
6 |
Correct |
25 ms |
3800 KB |
Output is correct |
7 |
Correct |
41 ms |
4924 KB |
Output is correct |
8 |
Correct |
43 ms |
5064 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Execution timed out |
2086 ms |
348 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
17 ms |
4012 KB |
Output is correct |
4 |
Correct |
22 ms |
2400 KB |
Output is correct |
5 |
Correct |
39 ms |
4804 KB |
Output is correct |
6 |
Correct |
25 ms |
3800 KB |
Output is correct |
7 |
Correct |
41 ms |
4924 KB |
Output is correct |
8 |
Correct |
43 ms |
5064 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Execution timed out |
2086 ms |
348 KB |
Time limit exceeded |
12 |
Halted |
0 ms |
0 KB |
- |