Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register
欢迎参加IJCAI 2020麻将智能体竞赛,大奖等你拿!Welcome to IJCAI 2020 Mahjong AI competition with amazing prizes! | 北京大学《ACM/ICPC大学生程序设计竞赛训练》暑期课面向全球招生!

用线段树老超时~~实在无奈~~~请各位大牛帮忙看看~~~

Posted by owenlee at 2008-05-27 09:50:00 on Problem 2828
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator