/************************************************************** User: error408 Language: C/C++ School: SSDUT Saying: Do one thing at a time,and do well. ****************************************************************/ #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #pragma comment(linker,"/STACK:102400000,102400000") #define clr(s,x) memset((s),(x),sizeof(s)) #define lson l,m,rt<<1 #define rson m+1,r,rt<<1|1 #define lowbit(x) (x&(-x)) #define PB push_back #define RL(N) scanf("%I64d",&N) #define RLL(L,R) (RL(L),RL(R)) #define lch(x) x<<1 #define rch(x) x<<1|1 #define lrt rt<<1 #define rrt rt<<1|1 typedef long long LL; typedef unsigned int uint; typedef unsigned long long ULL; typedef vector vint; typedef vector vstring; /************************************END DEFINE*********************************************/ const int maxn = 5e4 + 1000; int a[maxn]; int sum[maxn<<2]; int ans[maxn]; void pushup(int rt){ sum[rt]=sum[lrt]+sum[rrt]; } void build(int l,int r,int rt){ sum[rt]=1; if(l==r) return ; int m=(r+l)>>1; build(lson); build(rson); pushup(rt); } int query(int l,int r,int rt,int pos){ if(l==r) return l; int m=(r+l)>>1; if(pos<=sum[lrt]) return query(lson,pos); else return query(rson,pos-sum[lrt]); } void update(int l,int r,int rt,int pos){ if(l==r){ sum[rt]=0; return ; } int m=(r+l)>>1; if(pos<=m) update(lson,pos); else update(rson,pos); pushup(rt); } int main(){ int t; scanf("%d",&t); while(t--){ int n; scanf("%d",&n); build(1,n,1); for(int i=0;i=0;i--){ int k; if(i!=0) k=a[i]-a[i-1]; else k=a[i]; k=sum[1]-k; ans[i]=query(1,n,1,k); update(1,n,1,ans[i]); } for(int i=0;i