#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define sp ' '
#define en '\n'
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
using namespace std;
const int N = 2e5 + 2;
const int inf = 2e9;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n; cin >> n;
vector<ll> a(n), b(n, 1);
for (int i = 0; i < n; i++) {
cin >> a[i];
while (true) {
if (a[i] % 2 == 1) break;
else {b[i] *= 2; a[i] /= 2;}
}
if (i > 0) b[i] += b[i - 1];
}
int q; cin >> q;
while (q--) {
ll x; cin >> x;
int l = 0, r = n - 1, ans = -1;
while (l <= r) {
int mid = l + r >> 1;
if (x <= b[mid]) {
ans = mid;
r = mid - 1;
}
else l = mid + 1;
}
cout << a[ans] << en;
}
return 0;
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:30:25: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
30 | int mid = l + r >> 1;
| ~~^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
20 ms |
3976 KB |
Output is correct |
4 |
Correct |
37 ms |
2392 KB |
Output is correct |
5 |
Correct |
57 ms |
5440 KB |
Output is correct |
6 |
Correct |
34 ms |
4084 KB |
Output is correct |
7 |
Correct |
50 ms |
5492 KB |
Output is correct |
8 |
Correct |
51 ms |
5660 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
320 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
320 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
320 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
20 ms |
3976 KB |
Output is correct |
4 |
Correct |
37 ms |
2392 KB |
Output is correct |
5 |
Correct |
57 ms |
5440 KB |
Output is correct |
6 |
Correct |
34 ms |
4084 KB |
Output is correct |
7 |
Correct |
50 ms |
5492 KB |
Output is correct |
8 |
Correct |
51 ms |
5660 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
320 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
320 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
320 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
27 ms |
2964 KB |
Output is correct |
24 |
Correct |
33 ms |
5196 KB |
Output is correct |
25 |
Correct |
66 ms |
8808 KB |
Output is correct |
26 |
Correct |
59 ms |
5488 KB |
Output is correct |
27 |
Correct |
57 ms |
5552 KB |
Output is correct |
28 |
Correct |
91 ms |
9184 KB |
Output is correct |
29 |
Correct |
104 ms |
8676 KB |
Output is correct |
30 |
Correct |
41 ms |
3660 KB |
Output is correct |
31 |
Correct |
107 ms |
9164 KB |
Output is correct |