49 provincial election simulation solution to a problem

A. Manager

The problem is the number of bits per sub-tree.

The modifying operation is changed every time the maximum value.

So as far as the value before the modification is $ x $, if $ x $ is greater than an ancestor of the median, then no effect on the median, otherwise it will update the right answer for a median number can be.

As long as pre-treatment and then found out the two answers.

Every action is to ask the ancestors of a chain, that as long as a data structure to maintain it, to support a single point of modification query interval to get away.

 

B. GCD re-broadcasting

First, to get a Mobius inversion, then the problem is converted to a multiple of $ X $ $ count of $ \ as GCD.

For each $ x $, each of the sequences into three categories.

Are integral $ \ gcd $ is a multiple of $ x $, some prefixes $ \ gcd $ to $ x $ multiples, there are some suffixes $ \ gcd $ to $ x $ multiples.

Then interval of $ X $ $ $ GCD multiples can be divided into several categories.

For each class, the number of combinations were calculated using the line.

 

C. dict

To count the number of strings lexicographically strictly less than another string, it would put forward a determined bit.

How many to enumerate in front of the original strings are the same, then the Imperial bit less than the current string comparison of the current bit.

And then found each number can fill is not much to do violence is $ O (nm) $ with a number of combinations, in fact, the process will continue to fill in the number corresponding to the division of the binary tree.

So find out a $ dsu on tree $, every two possibilities: the current collection, complete works to reduce complement routine.

Guess you like

Origin www.cnblogs.com/skyh/p/12520583.html