-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathI.cpp
More file actions
32 lines (32 loc) · 772 Bytes
/
Copy pathI.cpp
File metadata and controls
32 lines (32 loc) · 772 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main(){
int tc;
cin>>tc;
while(tc--){
int H,N;
cin>>H>>N;
while(N--){
ll tmp;cin>>tmp;
if(tmp+1==(1<<H)){
cout<<"-1 ";
continue;
}
int ans = 0;
int root;
while(true){
if((tmp+1)==((tmp+1)&-(tmp+1)) || (2*tmp+1) == ((2*tmp+1)&-(2*tmp+1)))break;
for(root = 1;root<=tmp;root<<=1);
root>>=1;root--;
tmp-=root;
if(tmp==root)break;
ans += root;
}
if(tmp%2)ans+=2*tmp+1;
else ans+=tmp+1;
cout<<ans<<" ";
}
cout<<endl;
}
}