It should be the single point update of the Line Segment tree.
But at the beginning, it gave me the illusion that I was also drunk with a two-dimensional line segment tree.
Tree [root]. x // X = L | r indicates that the root node represents the range of L-> r.
Tree [root]. leftlen // indicates the maximum number of consecutive grids in the interval where the root node is located.
What's even more depressing is that I use CIN cout to write it, even if it says "cin. sync_with_stdio (false)" or "tle...
I am also speechless. I used to be effective on HDU...
Then I changed it to scanf printf...
1 #include <iostream> 2 #include <algorithm> 3 using namespace std; 4 5 const int size = 200010; 6 struct data 7 { 8 int L; 9 int R;10 int leftLen;11 }tree[size*4]; 12 13 void build( int root , int L , int R , int w )14 {15 int Mid = ( R + L ) >> 1;16 tree[root].L = L;17 tree[root].R = R;18 tree[root].leftLen = w;19 if( L==R )20 {21 return ;22 }23 build( root<<1 , L , Mid , w );24 build( root<<1|1 , Mid+1 , R , w );25 }26 27 void pushUp( int root )28 {29 tree[root].leftLen = max( tree[root<<1].leftLen , tree[root<<1|1].leftLen ); 30 }31 32 void update( int root , int w )33 {34 int ans;35 if( tree[root].L == tree[root].R )36 {37 tree[root].leftLen -= w;38 cout << tree[root].L << endl;39 return ;40 } 41 if( tree[root<<1].leftLen >= w )42 update( root<<1 , w );43 else if( tree[root<<1|1].leftLen >= w )44 update( root<<1|1 , w );45 pushUp( root );46 }47 48 int main()49 {50 cin.sync_with_stdio(false);51 int h , w , n;52 while( cin >> h >> w >> n )53 {54 h = min( h , n );55 build( 1 , 1 , h , w );56 while( n-- )57 {58 cin >> w;59 if( tree[1].leftLen < w )60 cout << -1 << endl;61 else62 update( 1 , w );63 }64 }65 return 0;66 }
View code
I am still sticking to the Tle code here, but I prefer the style of CIN cout === _
Today:
You are like a sunset
They forgot what you looked like in the sun.
HDU -- 2795 -- is also a line segment tree