[Weekly summary] data structure (1)

Source: Internet
Author: User

Start learning algorithms again this week, starting with the data structure. This week I learned the basic data structure. I focused on online segment trees and tree arrays. But I also read some other advanced data structure algorithms, I hope to have some questions next week.

I have been impressed with this week:

No.1 poj 2155 Matrix

This question is actually a problem of converting an actual model to an algorithm model, which can be simplified to a one-dimensional condition. Suppose Now flip [a, B], you can put the position (A-1)-1, position B + 1 on the array, so that a point is flipped several times, you only need to calculate the sum of the array from position 1 to the position of this point. The time complexity of log (n) can be achieved by using a tree array. This is actually a statistical problem.

No. 2 war field Statistical System (East China Normal University OJ 1246)

I think this question is more important for modeling. Because the question will certainly not be tested by your bare algorithm, you need to transfer an actual problem to a model that can be solved using a known algorithm, and then use the algorithm to solve it efficiently.

For example, in [a, B], a soldier with a defense of C can be regarded as a (A, 1, B, c) (the first two digits in the lower left corner and the last two digits in the upper right corner). When you delete the rectangle (A, 1, B, c), you can use the rectangle cut in the middle. But although he knew that this was actually a two-dimensional line segment tree, he did not expect how to implement it. Later, I used a four-point tree. Although it was written, it exceeded the memory. Later, let's look at the expert code and find that there is no need to use any data structure. You just need to write down the rectangle added each time and traverse the known rectangle when deleting it, because there are not many rectangles. This method sounds obvious, but I did not expect it. Ah, IQ is still hard to hurt.

This solution reminds me of the fourth question of codeforces round #136 div2, that is, div1's second question. No advanced algorithms are used to obtain all the data that meets the conditions, and then update the data in sequence.

No. 3 spoj 61 brackets

For a sequence of parentheses, I can use a pair of numbers to represent (a, B). A represents the unmatched right parenthesis on the left of the sequence, and B represents the unmatched left parenthesis on the right, you can use the line segment tree to calculate the sequence of each segment. Then a large sequence can be updated through its two subsequences.

Through this week's study, I think the line segment tree is actually a embodiment of the binary method and multiplication method. I can break down an actual question into many subquestions, and then get the answers to the big questions from these subquestions. We only need to modify some subquestions, then, the final answer is updated constantly.

Tree arrays have advantages in Statistics

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.