#include <iostream>
using namespace std;
struct sirNou{
long long s,e,val;
} v[200001];
void gasesteVal(long long a,long long i){
long long put=1;
while(a%2==0){
put*=2;
a/=2;
}
v[i].s=v[i-1].e+1;
v[i].e=v[i-1].e+put;
v[i].val=a;
}
int main()
{
long long n,i,q,st,dr,mij,a,gas;
cin>>n;
for(i=1;i<=n;i++){
cin>>a;
if(a%2==1){
v[i].val=a;
v[i].s=v[i].e=v[i-1].e+1;
}else{
gasesteVal(a,i);
}
}
cin>>q;
for(i=0;i<q;i++){
cin>>gas;
st=1;dr=n;
while(st<=dr){
mij=(st+dr)/2;
if(v[mij].s<=gas && v[mij].e>=gas){
cout<<v[mij].val<<"\n";
break;
}else if(v[mij].s>gas){
dr=mij-1;
}else{
st=mij+1;
}
}
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
72 ms |
4812 KB |
Output is correct |
4 |
Correct |
199 ms |
1604 KB |
Output is correct |
5 |
Correct |
299 ms |
5324 KB |
Output is correct |
6 |
Correct |
146 ms |
4280 KB |
Output is correct |
7 |
Correct |
285 ms |
5324 KB |
Output is correct |
8 |
Correct |
290 ms |
5284 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
2 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
2 ms |
340 KB |
Output is correct |
12 |
Correct |
2 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
2 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
72 ms |
4812 KB |
Output is correct |
4 |
Correct |
199 ms |
1604 KB |
Output is correct |
5 |
Correct |
299 ms |
5324 KB |
Output is correct |
6 |
Correct |
146 ms |
4280 KB |
Output is correct |
7 |
Correct |
285 ms |
5324 KB |
Output is correct |
8 |
Correct |
290 ms |
5284 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
2 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
2 ms |
340 KB |
Output is correct |
20 |
Correct |
2 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
2 ms |
340 KB |
Output is correct |
23 |
Correct |
177 ms |
3240 KB |
Output is correct |
24 |
Correct |
151 ms |
6288 KB |
Output is correct |
25 |
Correct |
351 ms |
10316 KB |
Output is correct |
26 |
Correct |
221 ms |
6536 KB |
Output is correct |
27 |
Correct |
172 ms |
6664 KB |
Output is correct |
28 |
Correct |
374 ms |
10728 KB |
Output is correct |
29 |
Correct |
353 ms |
10260 KB |
Output is correct |
30 |
Correct |
253 ms |
3888 KB |
Output is correct |
31 |
Correct |
377 ms |
10700 KB |
Output is correct |