The CDQ of Meng Meng da-Zhi

Source: Internet
Author: User

The idea of CDQ is very simple, that is, each time the recursive processing in the left half of the interval and the right half of the answer of the contribution, and then like a merge sort the left half and half together, incidentally, the left half of the interval of the changes in the right half of the border between the query made contribution. Merging sort to reverse order is the simplest application of CDQ division.

It is easy to analyze that these conditions need to be met when applied to CDQ division: Each change is independent of the impact of each inquiry; We can quickly count out a bunch of specified modification operations to a total contribution to a query.

Classic applications such as several points.

Bzoj 3262: Flowers bloom on the mo

Is the simplest three-dimensional points, this time directly to the first dimension of a sequence, and then the second dimension on the CDQ Division, when the merger if a point of inquiry originally belonged to the right half of the border, Then all the original left half of the interval (that is, the first Werbe query point Large) and after the merger in front of it (that is, the second Werbe query point Large) and the third Werbe ask the point of the big point will have a 1 contribution to the inquiry point. So just need to sweep the merged sequence from small to large, and then use a tree array to save the current part of the left half and the third dimension is greater than the number of X, then each inquiry point in this merger can be done O (logn) query.

Tsinsen A1485. Catch the Penguins Catch the Penguin (Zhang Yaotao)

Four-dimensional points

There are a lot of ways to do it, a simple example of a three-dimensional points and then open a tree-like array of balanced tree.

YY CDQ Division of the CDQ Division of the practice, but also very simple. Then the above three-dimensional one said, we merge after the left and right interval to join in the POS query answer is all the current position is less than the POS and the original point between the left half border, and this is converted to a three-dimensional points problem! The original in the left half of all the query and the original right half of all the changes in the current is meaningless to delete the good.

A very good place to do this is to always garvey the number plus, each plus one dimension on a layer of CDQ, time complexity set a log, but its advantage is that space complexity is always O (n) o Ah, Tree sets are more difficult to write when set to more dimensions but this is always a good thing.

The CDQ of Meng Meng da-Zhi

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.