| ||||||||||
Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
用线段树老超时~~实在无奈~~~请各位大牛帮忙看看~~~#include<iostream> using namespace std; int A[ 200000 + 1 ][ 2 ], C[ 600000 + 3 ], result[ 200000 + 1 ]; inline void BuildTree( int i, int p ,int q ) { if( p == q ) { C[ i ] = 1; return; } C[ i ] = q - p + 1; int L, R, Mid; Mid = ( p + q ) >> 1; L = ( i << 1 ) + 1; R = L + 1; BuildTree( L, p, Mid ); BuildTree( R, Mid + 1, q ); } inline void OutOfQueue( int i, int p, int q, int position ) { C[ i ]--; if( p == q ) { result[ p ] = A[ position ][ 1 ]; return; } int L, R, Mid; Mid = ( p + q ) >> 1; L = ( i << 1 ) + 1; R = L + 1; if( C[ L ] > A[ position ][ 0 ] ) OutOfQueue( L, p, Mid, position ); else { A[ position ][ 0 ] -= C[ L ]; OutOfQueue( R, Mid + 1, q, position ); } } int main() { int n; while( cin >> n ) { for( int i = 0; i < n; i++ ) cin >> A[ i ][ 0 ] >> A[ i ][ 1 ]; BuildTree( 0, 1, n ); for( int i = n - 1; i >= 0; i-- ) OutOfQueue( 0, 1, n, i ); for( int i = 1; i <= n; i++) cout << result[ i ] << ' '; cout << endl; } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator