1 2
1 3 2
1 3 2 4
1 5 2 4 3
1 4 2 6 3 5
1 6 2 5 3 7 4
1 5 2 7 3 6 4 8
1 9 2 6 3 8 4 7 5
1 6 2 10 3 7 4 9 5 8
规律题是真的让我望尘莫及。
#include<bits/stdc++.h>
#define PI acos(-1.0)
#define pb push_back
using namespace std;
typedef long long ll;
const int N=2e5+5;
const int MOD=1e9+7;
const int INF=0x3f3f3f3f;
int main(void){
ll n,q,p,t;
cin>>n>>q;
t=n;
while(q--){
scanf("%I64d",&p);
// cout <<"p="<<p<<endl;
if(p%2==1){
printf("%lld\n",p/2+1);
}
else{
ll nn=n=t;
while(p%2==0){
ll cnt=p/2;
p-=cnt*2;
n-=cnt;
if(p==0) p+=n;
}
printf("%I64d\n",p/2+1 + nn-n);
}
}
return 0;
}