#include<bits/stdc++.h>
#define int long long
#define ms(v) memset(v, -1, sizeof v)
#define pi pair<int, int>
#define pb push_back
#define fr first
#define sc second
#define srt(v) sort(v.begin(), v.end())
#define INF 1e15
using namespace std;
int n;
vector <pair <pi, int>> v;
void buscab(int x){
int l = 0, r = v.size()-1;
int res = -1;
while(l <= r){
int mid = (l+r) >> 1;
if(v[mid].fr.fr <= x and x <= v[mid].fr.sc){
res = mid;
break;
}
else if(v[mid].fr.sc < x){
l = mid+1;
}
else{
r = mid;
}
}
cout << v[res].sc << "\n";
return;
}
int32_t main(){
ios::sync_with_stdio(false); cin.tie(0);
cin >> n;
int st = 1;
for(int i = 1;i <= n;i++){
int x;
cin >> x;
int con = 1;
while(x % 2 == 0){
x /= 2;
con *= 2;
}
v.pb({{st, st + con - 1}, x});
st = st + con;
}
int q;
cin >> q;
for(int i = 1;i <= q;i++){
int x;
cin >> x;
buscab(x);
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
22 ms |
7004 KB |
Output is correct |
4 |
Correct |
32 ms |
2756 KB |
Output is correct |
5 |
Correct |
54 ms |
7224 KB |
Output is correct |
6 |
Correct |
32 ms |
7076 KB |
Output is correct |
7 |
Correct |
53 ms |
7216 KB |
Output is correct |
8 |
Correct |
58 ms |
7352 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
328 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 |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
324 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
22 ms |
7004 KB |
Output is correct |
4 |
Correct |
32 ms |
2756 KB |
Output is correct |
5 |
Correct |
54 ms |
7224 KB |
Output is correct |
6 |
Correct |
32 ms |
7076 KB |
Output is correct |
7 |
Correct |
53 ms |
7216 KB |
Output is correct |
8 |
Correct |
58 ms |
7352 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
328 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 |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
324 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
29 ms |
3428 KB |
Output is correct |
24 |
Correct |
42 ms |
8016 KB |
Output is correct |
25 |
Correct |
68 ms |
10484 KB |
Output is correct |
26 |
Correct |
48 ms |
6708 KB |
Output is correct |
27 |
Correct |
42 ms |
8124 KB |
Output is correct |
28 |
Correct |
89 ms |
11100 KB |
Output is correct |
29 |
Correct |
86 ms |
10336 KB |
Output is correct |
30 |
Correct |
42 ms |
4076 KB |
Output is correct |
31 |
Correct |
80 ms |
10796 KB |
Output is correct |