#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<long long, long long> pll;
typedef pair<int,int> pii;
typedef vector<long long> vl;
typedef vector<int> vi;
int n, q;
vi arr, two;
int main(){
cin>>n;
arr.resize(n);
two.resize(n);
for(int i = 0; i < n; i++) cin>>arr[i];
vector<pii> segments;
vl val;
int last = -1;
// reverse(arr.begin(), arr.end());
for(int i = 0; i < n; i++){
ll x = arr[i];
two[i]=1;
while(x%2 == 0){
two[i]*=2;
x/=2;
}
segments.pb(mp(last+1, last + two[i]));
val.pb(x);
last += two[i];
}
ll pref[n];
pref[0] = segments[0].second + 1;
for(int i = 1; i < n; i++)
pref[i] = pref[i-1] + segments[i].second - segments[i].first+1;
int q;
cin>>q;
while(q--)
{
ll x;
cin>>x;
int l = 0, r = n-1, pos;
while(l <= r){
int mid = l + (r-l)/2;
if(pref[mid] >= x){
pos = mid;
r = mid - 1;
}
else
l = mid+1;
}
cout<<val[pos]<<endl;
}
return 0;
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:52:16: warning: 'pos' may be used uninitialized in this function [-Wmaybe-uninitialized]
52 | cout<<val[pos]<<endl;
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
88 ms |
7260 KB |
Output is correct |
4 |
Correct |
246 ms |
3312 KB |
Output is correct |
5 |
Correct |
333 ms |
8844 KB |
Output is correct |
6 |
Correct |
188 ms |
6900 KB |
Output is correct |
7 |
Correct |
350 ms |
8816 KB |
Output is correct |
8 |
Correct |
362 ms |
9092 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 |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
296 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
304 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
2 ms |
312 KB |
Output is correct |
9 |
Incorrect |
1 ms |
300 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
88 ms |
7260 KB |
Output is correct |
4 |
Correct |
246 ms |
3312 KB |
Output is correct |
5 |
Correct |
333 ms |
8844 KB |
Output is correct |
6 |
Correct |
188 ms |
6900 KB |
Output is correct |
7 |
Correct |
350 ms |
8816 KB |
Output is correct |
8 |
Correct |
362 ms |
9092 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
296 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
304 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
2 ms |
312 KB |
Output is correct |
17 |
Incorrect |
1 ms |
300 KB |
Output isn't correct |
18 |
Halted |
0 ms |
0 KB |
- |