【UVA】11525-Permutation(线段树水题)
2014-10-13 14:26
411 查看
14343652 | 11525 | Permutation | Accepted | C++ | 0.175 | 2014-10-13 06:27:29 |
#include<cstdio> #include<cstring> #include<algorithm> using namespace std; #define lson pos<<1 #define rson pos<<1|1 const int maxn = 55555; int tr[maxn << 2]; int num[maxn << 2]; int array[maxn]; int sz,ss; void BuildTree(int L,int R,int pos){ if(L == R){ tr[pos] = 1; num[pos] = sz++; return; } int m = (L + R) >> 1; BuildTree(L,m,lson); BuildTree(m + 1,R,rson); tr[pos] = tr[lson] + tr[rson]; return; } void UpDate(int aim,int l,int r,int pos){ if(l == r){ array[ss++] = num[pos]; tr[pos] = 0; return; } int m = (l + r) >> 1; if(tr[lson] >= aim) UpDate(aim,l,m,lson); else UpDate(aim - tr[lson],m + 1,r,rson); tr[pos] = tr[lson] + tr[rson]; } int main(){ int T; scanf("%d",&T); while(T--){ int n,s; sz = 1; ss = 0; scanf("%d",&n); BuildTree(1,n,1); for(int i = 0; i < n; i++){ scanf("%d",&s); UpDate(s + 1,1,n,1); } for(int i = 0; i < ss; i++){ if(i) printf(" "); printf("%d",array[i]); } printf("\n"); } return 0; }
相关文章推荐
- UVa 11525 - Permutation (线段树 树状数组 康托展开式)
- uva 11525 - Permutation(线段树)
- UVa 11525 Permutation (线段树)
- UVA 11525 Permutation(线段树第K大数字问题)
- UVaLive 11525 Permutation (线段树)
- UVA 11525 - Permutation(树状数组)
- UVA 11525 Permutation(树状数组)
- uva 10252 - Common Permutation 字符串水题
- uva 10252 - Common Permutation 字符串水题
- UVA 11525 好大好大的排列(线段树)
- Uva-11525-Permutation
- UVA 11525 Permutation (树状数组+YY)
- UVA 11525 Permutation
- uva 11525 Permutation
- UVA 11525 Permutation(树状数组)
- uva 11525(线段树)
- uva 11525 Permutation
- 线段树优化康拓展开uva11525
- UVa 11525 Permutation(二分+树状数组)
- UVA 11525 Permutation(树状数组)