题意
一个序列初始为 1 _ 2 _ 3 _ . . . _ n − 1 _ n 1\_2\_3\_...\_n-1\_n 1_2_3_..._n−1_n(_为空),每次操作会把最后一个数往左移到第一个空,操作持续到无法移动为止(即1~n把前面全占满,没有空了), q q q 次询问位置 P P P 的值 ( 1 ≤ P ≤ n 1\le P \le n 1≤P≤n)
操作如下图所示
题解
感性的理解一下,操作到最后,1~n 奇数位上的数是没有移动过的,因为
处理到
n
2
\cfrac{n}{2}
2n 时,序列长这样:
1
_
2
_
3
_
.
.
_
n
2
a
b
c
d
.
.
_
_
_
_
_
1\_2\_3\_..\_\cfrac{n}{2}abcd..\_\_\_\_\_
1_2_3_.._2nabcd.._____,后一半的数会连在一起,然后把前面的空全填上
同理对于后一半的数,处理到 n 4 \cfrac{n}{4} 4n时,奇数位置也没变,对于后一半的后一半也是。。。。
所以就一直往后找,把 P 加回去直到它是奇数位置为止
#include<iostream>
#include<sstream>
#include<string>
#include<queue>
#include<map>
#include<unordered_map>
#include<set>
#include<vector>
#include<stack>
#include <utility>
#include<list>
#include<bitset>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<iomanip>
#include<time.h>
#include<random>
using namespace std;
#include<ext/pb_ds/priority_queue.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
using namespace __gnu_pbds;
#include<ext/rope>
using namespace __gnu_cxx;
#define int long long
#define PI acos(-1.0)
#define eps 1e-9
#define lowbit(a) ((a)&-(a))
#define mid ((l+r)>>1)
#define mem(x,y) memset(x,y,sizeof x)
const int mod = 1e9+7;
int qpow(int a,int b){
int ans=1;
while(b){
if(b&1)ans=(ans*a)%mod;
a=(a*a)%mod;
b>>=1;
}
return ans;
}
const int INF = 0x3f3f3f3f;
const int N = 1e6+10;
#define endl '\n'
signed main(){
//freopen("C:\\Users\\egoist\\Desktop\\in.txt","r",stdin);
//freopen("C:\\Users\\egoist\\Desktop\\out.txt","w",stdout);
std::ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
int n,q; cin>>n>>q;
while(q--){
int p; cin>>p;
while(!(p&1))p+=(n-(p>>1));
cout<<((p>>1)+1)<<endl;
}
}