标签:
1 #include <stdio.h> 2 #include <algorithm> 3 #define lson o << 1 , l , mid 4 #define rson o << 1 | 1 , mid + 1 , r 5 using namespace std; 6 7 int h , w , n ; 8 int maxn[1000000] ; 9 int x ; 10 11 void build ( int o , int l , int r ) 12 { 13 maxn[o] = w ; 14 if ( l == r ) { 15 return ; 16 } 17 int mid = ( l + r ) >> 1 ; 18 build ( lson ) ; 19 build ( rson ) ; 20 } 21 22 int query ( int o , int l , int r ) 23 { 24 if ( l == r ) { 25 maxn[o] -= x ; 26 return l ; 27 } 28 int mid = ( l + r ) >> 1 , ret ; 29 if ( x <= maxn[o << 1] ) { 30 ret = query ( lson ) ; 31 } 32 else { 33 ret = query ( rson ) ; 34 } 35 maxn[o] = max ( maxn[o << 1] , maxn[o << 1 | 1] ) ; 36 return ret ; 37 } 38 int main () 39 { 40 // freopen ( "a.txt" , "r" , stdin ) ; 41 while ( scanf ("%d%d%d" , &h , &w , &n ) != EOF ) { 42 if ( h > n ) 43 h = n ; 44 build ( 1 , 1 , h ) ; 45 for (int i = 1 ; i <= n ; i++ ) { 46 scanf ( "%d" , &x ) ; 47 if ( x > maxn[1] ) { 48 printf ("-1\n") ; 49 } 50 else { 51 printf ("%d\n" , query ( 1 , 1 , h ) ) ; 52 } 53 } 54 } 55 return 0 ; 56 }
标签:
原文地址:http://www.cnblogs.com/get-an-AC-everyday/p/4276401.html