本文主要是介绍spoj 227,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
留着
#include <cstdio>
#include <cstring>
#include <cstdlib>#define lson l, m, rt << 1
#define rson m + 1, r, rt << 1 | 1const int MAXN = 200010;int pos[MAXN];
int sum[MAXN << 2];// = MAXN*4
int ans[MAXN];
int N, id;void build( int l, int r, int rt )
{sum[rt] = r - l + 1;if ( l == r ) return;int m = ( l + r ) >> 1;// = (l+r)/2build( lson );build( rson );return;
}void Update( int po, int l, int r, int rt )
{--sum[rt];if ( l == r ){id = l;return;}int m = ( l + r ) >> 1;// = (l+r)/2if ( po <= sum[rt << 1] ) Update( po, lson ); // = rt*2else Update( po - sum[rt << 1], rson ); // = rt*2return;
}int main()
{int T;scanf( "%d", &T );while ( T-- ){scanf( "%d", &N );build( 1, N, 1 );for ( int i = 1; i <= N; ++i )scanf( "%d", &pos[i] );for ( int i = N; i > 0; --i ){int addr = i - pos[i]; //还剩几个数Update( addr, 1, N, 1 );ans[i] = id;//printf( "%d\n", id );}printf( "%d", ans[1] );for ( int i = 2; i <= N; ++i )printf( " %d", ans[i] );puts("");}return 0;
}
这篇关于spoj 227的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!