Cojs Crazy Magic Tree Crazy color sequence Puzzle report

Source: Internet
Author: User

The Crazy Magic Tree

A variety of operations a hodgepodge of ghost animal data structure problems

First we notice that the shape of the tree is semi-random.

We can divide the tree into blocks, dividing the tree into chunks.

For each block we maintain an add tag that represents the increment

Maintain a vis mark indicating the amount of coverage

Note the decentralization of the mark and the processing between the two marks

Then we sort each block, and maintain the order within the block

This can be done for each query if it involves a complete block of two points

Otherwise brute force query

This time complexity is O (n*sqrt (n) *log (n))

Crazy color Sequence

Very old topic, if I get rid of mandatory online, I know there are five different methods.

The first way is that MO team

The second approach is to take the query offline after sorting the scan line + Tree array

The third approach is to calculate the position of each color last occurrence, within the block block of the Order + two points

The fourth approach is a tree-set tree, similar to the principle of chunking.

The fifth is the code that I write, we calculate the position of each color last occurrence of the pre

Then each query is equivalent to asking how many points [l,r] have a pre value of <l

And then it's the bare topic that can persist the line tree.

Cojs Crazy Magic Tree Crazy color sequence Puzzle report

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.