Mayor's posters problem handling

Source: Internet
Author: User

Question perception:

/*
The idea of this question is to first open an array,
Construct a line segment tree and update it each time.
Finally, we only need to check
The numbers left in the outermost layer are counted.
Then return the result.
This question is not difficult, and the idea is very clear,
However, there are still many problems in the process.
Because the data volume is too large, it is likely to time out after processing.
I feel unfair about this. Why input data from two endpoints?
We need to handle a large range of corresponding operations, and eventually cause timeout.
This is why we have encountered similar problems before,
I think this problem can be summarized to solve the problem.

*/

In this question, we need to use the line segment tree and the idea of discretization. The line segment tree won't be explained here. The only thing that becomes more complicated than before is the lazy mark. In this way, the access time can be reduced. The idea of Discretization can reduce space usage. So what is the so-called discretization? I have collected some information here, and I am doing some exercises on my own. I found that it can greatly reduce the overhead of space, and it is also possible to reduce the overhead of time.

 

In layman's terms, discretization is the compression interval, which maps the original long interval to the new short interval, but the coverage relationship before and after the compression remains unchanged. For example:

There is a number axis from 1 to 10 (the length is 9). Given four intervals [2, 4] [3, 6] [8, 10] [6, 9], the overwrite relationship means that the latter overwrites the former, the color of each interval is 1 2 3 4 in sequence.

Now we extract the eight endpoints of the four intervals, 2 4 3 6 8 6 9

Delete the same endpoint. If the same endpoint is 6, the remaining two are 4 3 6 8 10 9.

Sort them in ascending order. The values are 2, 3, 4, 6, 8, 9, and 10.

Then create a ing

2 3 4 6 8 9 10

When there are too many other users

1 2 3 4 5 6 7

The new four intervals are [1, 3] [2, 4] [5, 7] [4, 6], and the overwrite relationship is not changed. The new number axis is 1 to 7, that is, the length of the original number axis is compressed from 9 to 6. Obviously, the line segment tree of [] is more space-saving than the line segment tree, the search speed is faster, but the results are consistent.

 

Note that the same endpoint must be removed before sorting. This reduces the number of elements involved in sorting and saves time.

 

Attachment: the maximum number of posters is 10000, that is, the maximum length of the new number axis mapped by its endpoint is 20000. Therefore, when creating a discrete array DIS with a length of 1 QW, the unsigned short type can be used, and its ing value can be up to 20000, which saves space overhead.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.