#include <bits/stdc++.h>
using namespace std;
int n,m;
struct cake{
int len;
long long l,r;
}a[200005];
int main(){
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cin>>n;
a[0].r=0;
for (int i=1;i<=n;i++){
cin>>a[i].len;
long long cnt=1;
while (a[i].len%2==0){
a[i].len/=2;
cnt*=2;
}
a[i].l=a[i-1].r+1;
a[i].r=a[i-1].r+cnt;
}
cin>>m;
while (m--){
long long t,ptl=1,ptr=n,mid;
cin>>t;
while (ptl<=ptr){
mid=(ptl+ptr)/2;
if (a[mid].l<=t && a[mid].r>=t){
cout<<a[mid].len<<"\n";
break;
}
else if (a[mid].l>t) ptr=mid-1;
else ptl=mid+1;
}
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
328 KB |
Output is correct |
3 |
Correct |
21 ms |
5524 KB |
Output is correct |
4 |
Correct |
32 ms |
2628 KB |
Output is correct |
5 |
Correct |
49 ms |
7060 KB |
Output is correct |
6 |
Correct |
30 ms |
5276 KB |
Output is correct |
7 |
Correct |
63 ms |
7084 KB |
Output is correct |
8 |
Correct |
50 ms |
7204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 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 |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
328 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 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
328 KB |
Output is correct |
3 |
Correct |
21 ms |
5524 KB |
Output is correct |
4 |
Correct |
32 ms |
2628 KB |
Output is correct |
5 |
Correct |
49 ms |
7060 KB |
Output is correct |
6 |
Correct |
30 ms |
5276 KB |
Output is correct |
7 |
Correct |
63 ms |
7084 KB |
Output is correct |
8 |
Correct |
50 ms |
7204 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
340 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 |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
328 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 |
3244 KB |
Output is correct |
24 |
Correct |
34 ms |
6352 KB |
Output is correct |
25 |
Correct |
72 ms |
10316 KB |
Output is correct |
26 |
Correct |
44 ms |
6512 KB |
Output is correct |
27 |
Correct |
63 ms |
6584 KB |
Output is correct |
28 |
Correct |
89 ms |
10700 KB |
Output is correct |
29 |
Correct |
78 ms |
10188 KB |
Output is correct |
30 |
Correct |
41 ms |
3884 KB |
Output is correct |
31 |
Correct |
81 ms |
10700 KB |
Output is correct |