The question to the problem can be found here:
Explanation:
1. It is a tricky one but easy to code if you understand it.
2. using the index of the array we can solve it.
3. First lets test your attention skill. Look at the IV Figure and then the I figure.
4. If the array index number is a odd number(see input) if you add one and divide by 2, you get the required answer(the value at that index)
5. On the other hand as long as the index number is even, do x+=n- x/2.
6. Do them in Bitwise so it will reduce a lot of time to run.
7. Happy Coding.
Code:
#include<bits/stdc++.h>
using namespace std;
int main(){
long long int n,q,x;
cin>>n>>q;
while(q--){
cin>>x;
while(!(x&1)){
x+=n-x/2;
}
cout<<(x+1>>1)<<endl;
}
return 0;}