Hotel.
Interval merge problem.
Description of the problem: N.N a room.
10 6
1 3
1 3
1 3
1 3
2 5 5
1 6
10 rooms
Interval Merging:
This type of topic asks for the longest continuous interval in the range that satisfies the conditions, so it is necessary to merge the bands of the left and right sons in the pushup.
This sentence. That's very reasonable.
Tree[] What is recorded in itself? Is the value of the longest continuous interval of the point. This definition. Not hard to come by.
From. Returns when this value is reached. Look at the results. Can be visually examined quickly. That is, the longest interval value is stored.
PS: I was thinking about it at first. The actual value of 1 of the lattice stores the interval value from this point onwards to the back. I was ignoring it. 1-10 a numerical definition of such a range.
How do we implement the merger?
Make three trees.
In fact, each node records three values, from the left side of the node to the right how many consecutive slots, from the right end of the node to how many consecutive empty space, the length of the longest continuous vacancy in the range of how many
void pushup (int rt,int m)
{
LSUM[RT] = lsum[rt<<1]; The longest continuous value of the node from the left to right interval = the longest continuous value from left to right of the left node.
RSUM[RT] = rsum[rt<<1|1];
if (lsum[rt] = = M-(M >> 1)) Lsum[rt] + = lsum[rt<<1|1];
if (rsum[rt] = = (M >> 1)) Rsum[rt] + = rsum[rt<<1];
Above is the information that updates the left and right intervals of the node.
The following is the information that updates the longest contiguous interval of the node.
MSUM[RT] = max (lsum[rt<<1|1] + rsum[rt<<1], Max (msum[rt<<1], msum[rt<<1|1]));
}
Interval merging problem