#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pi pair<int, int>
#define pii pair<int, pair<int, int> >
#define fi first
#define se second
int n,k;
int A[200005], B[200005], P[200005];
void solve(){
cin >> n;
for(int i=1;i<=n;i++)cin >> A[i];
for(int i=1;i<=n;i++){
B[i] = 1;
while(A[i]%2 == 0)A[i] /= 2, B[i]*=2;
P[i] = P[i-1] + B[i];
}
int q;cin >> q;
while(q--){
int x;cin >> x;
int s = 1, e = n, ans = 0;
while(s <= e){
int m = (s + e)/2;
if(P[m] < x)ans = m, s = m + 1;
else e = m - 1;
}
cout << A[ans+1] << '\n';
}
}
main(){
ios::sync_with_stdio(0);cin.tie(0);
int t = 1;
//cin >> t;
while(t--){
solve();
}
}
Compilation message
Main.cpp:33:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
33 | main(){
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
19 ms |
5084 KB |
Output is correct |
4 |
Correct |
29 ms |
2012 KB |
Output is correct |
5 |
Correct |
47 ms |
5596 KB |
Output is correct |
6 |
Correct |
28 ms |
4660 KB |
Output is correct |
7 |
Correct |
49 ms |
5628 KB |
Output is correct |
8 |
Correct |
47 ms |
5540 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 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 |
0 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
19 ms |
5084 KB |
Output is correct |
4 |
Correct |
29 ms |
2012 KB |
Output is correct |
5 |
Correct |
47 ms |
5596 KB |
Output is correct |
6 |
Correct |
28 ms |
4660 KB |
Output is correct |
7 |
Correct |
49 ms |
5628 KB |
Output is correct |
8 |
Correct |
47 ms |
5540 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
340 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 |
0 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
28 ms |
2448 KB |
Output is correct |
24 |
Correct |
34 ms |
4640 KB |
Output is correct |
25 |
Correct |
61 ms |
7132 KB |
Output is correct |
26 |
Correct |
42 ms |
4112 KB |
Output is correct |
27 |
Correct |
38 ms |
4388 KB |
Output is correct |
28 |
Correct |
72 ms |
6380 KB |
Output is correct |
29 |
Correct |
74 ms |
5660 KB |
Output is correct |
30 |
Correct |
39 ms |
1968 KB |
Output is correct |
31 |
Correct |
74 ms |
6100 KB |
Output is correct |