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 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
| #include<bits/stdc++.h> #define INF 0x3f3f3f3f #define DOF 0x7f7f7f7f #define endl '\n' #define mem(a,b) memset(a,b,sizeof(a)) #define debug(case,x); cout<<case<<" : "<<x<<endl; #define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0) typedef long long ll; using namespace std; const int maxn = 2e5 + 10; int a[maxn]; struct node{ ll len,l,r; bool operator<(const node& a)const { if(a.len==len) return a.l<l; else return a.len>len; } }; priority_queue<node>qt; void solve() {
ll n;cin>>n; qt.push({n,1,n}); for(int i=1;i<=n;++i){ node tmp=qt.top();qt.pop(); ll mid=(tmp.l+tmp.r)/2; a[mid]=i; ll len=tmp.len,l=tmp.l,r=tmp.r; if(len&1){ qt.push({len/2,l,mid-1}); qt.push({len/2,mid+1,r}); }else{ qt.push({len/2-1,l,mid-1}); qt.push({len/2,mid+1,r}); } } for(int i=1;i<=n;++i){ cout<<a[i]<<" "; } cout<<endl; } int main() { int t;cin>>t; while(t--){ solve(); } }
|