1. Preface
There are still a lot of things to learn today, data structure has been a lot of content. The fourth question is more water than a previous question, and the result is not written.
2. Trouble with R R
Approximate test instructions: Give a series of length n, a total of t operations, each time you can add an interval x, you can also find the leftmost and the right end of the series K, output distance.
Summary: When the exam is not written out, can only think of line tree, but apparently maintenance is dead. At first I heard that I was too much, but I didn't try it, probably because it wasn't used much. This problem is very good to use a sub-block, the time limit is 3s, can be too.
The puzzle: chunking. Because we need to find a value at the far left and a value at the far right, it's too cumbersome for a segment tree to maintain the position of a value. First of all, let's think about the wording of violence. Interval modification, direct for loop, find K, from left and right two times for loop. How to speed up? We consider dividing the sequence evenly into chunks to deal with each block.
Like the line segment tree, we in some cases, in order to reduce complexity, will give some temporarily do not need to modify or ask the operation of the interval first to make a mark, indicating that this paragraph will be added a certain number. Suppose that an increase of x is currently given to [L,r], which may span multiple blocks, be marked directly on the middle block, and direct violence and subtraction for blocks with no full coverage on the left and right sides.
The process of asking seems to be more complex than it is. Every time we make a change to a block, we can sort it from small to large (and vice versa), so we can answer it directly when we ask for a number in each block.
It doesn't seem like a very high-end thing, but its minimum complexity is much lower than the brute-force enumeration. Why is it called the lowest? Notice that the size of the tile is not defined by us. As can be seen from the above description, the size of the block does not seem to affect the correctness of the program, so we just need to find a most suitable size, so that the complexity of the lowest. In general, the size of the selection √n, you can also decide. The average complexity is O (t * (√n log (√n)), 3s is possible.
3, Card Mystery cards
Slightly.
4. Captain Squad
Approximate test instructions: give n points, each point has two values a[i],b[i]. A total of t inquiries, each query given two numbers, asked to find a number including the two numbers of a set, satisfies: the set of the highest i,b[i] and the other number of B's absolute value difference is less than or equal to K.
Exercises
[Puzzle + Summary]20151017 data structure