30 provincial election simulation solution to a problem

A. despite the wind and waves, sit back

In fact, a optimized violence.

First, the answer is obviously $ x ^ 3 $ can be converted into $ 3 $ bit simultaneous program number * weight summation.

When $ k <= 20 $, directly XOR fwt, then do a superset of the summation, $ C (k, 3) $ enumerated on the list.

This algorithm is not good cause is only concerned with three bits simultaneously, it does not need to consider it as a number or as exclusive fwt.

Consider bits into $ k $ $ $ NUM group, wherein each $ A $ bits.

Every enumeration three groups, then put the right group of three values ​​together and do it again XOR fwt.

After doing it again superset of the sum, $ a ^ 3 $ statistics about the contribution.

After the re-enumeration of two groups, one group were statistical contribution across several groups just fine.

In this case put the $ 2 ^ k $ and direct violence, the number of combinations $ C (k, 3) $ amortized for a moment, the complexity will be able to before.

 

B. despite the wind and waves, sit back (cont.)

It is an unexpected number theory.

Expression of the readily $ \ sum \ limits_ {i = 1} ^ {n} \ mu (i) (\ sum \ limits_ {j = 1} ^ {n / i} [gcd (i, j) = 1 ] * \ mu (j)) in the form of $.

At this point can be found then can not do, if the enumeration $ i $, at least $ O (n) $ is certainly not the people. If the enumeration point behind the contribution, $ n ^ 2 $ is also out of the question.

So in this case the treatment solution to a problem to consider in selecting a threshold value $ B $.

First for $ i \ in [1, B] $ statistics about violent direct answer.

Then the contribution of the other part belongs to $ j \ in [1, n / B] \ and \ k \ in [1, n / B] $ points of $ (j, k) $.

Enumeration point, and then statistically qualifying $ i $ how many. This time count found heavy, so to lose weight.

For ease of calculation, set $ f (n, a) = \ sum \ limits_ {i = 1} ^ n [gcd (i, a) = 1] * \ mu (i) $.

This function is required for enumeration $ i $ $ j, k $, when applicable. For the enumeration of $ j, k $ $ i $ seek time is also applicable.

For the calculation of $ f $ if $ a = 1 $, you can direct violence Du teach sieve, because only $ n $ roots and seed value, it lacks the complexity of the problem.

Otherwise, consider first taking $ a = low (a) $, then there is a formula

$$f(n,a)=\sum \limits_{d|a} f(n/d,d)$$

And probably prove to $ [i == 1] = \ sum \ limits_ {i | d} \ mu (i) $ similar.

Consider the contribution of $ i $, let $ gcd $ to $ g $, if $ g \ neq1 $, then it is the inclusion-exclusion out.

If the root of violence about the number of enumeration $ a $, then the complexity and ascended to heaven.

If $ n ln (n) $ pretreatment of all of the divisor, so the skies constants.

The correct approach is a pre-$ n loglog $ prime factors, and enumerations divisor determined.

Then found that when $ n * a $ relatively small, the number of calculations it is not worth a lot. So for such content directly dp process.

Dp method is to make $ g_ {i, j} = [gcd (i, j) = 1] $, the array can be derived directly by Decreases, and can directly engage dp array.

Then write constants or too ugly or not, have to frantically adjust parameters to AC.

 

C. can not have both fish and bear's paw

Using an array of properties. I.e. to $ I $ $ $ P_i even edges form a plurality of loops.

So consider how to find all the rims, then you can solve the problem by exchanging each ring.

First, a random mistake to row, so if $ count $ exchange value means that there appears rims.

After the good practice is divide and conquer, only when the memory range in the rims when recursively.

The question is how grouping. The method of construction is that the solution to a problem, the operations will be $ X $ $ i + j \ equiv x \ pmod {n-1} $ side $ (i, j) $ grouped.

For $ 2i \ equiv x \ pmod {n-1} $, in particular adding edge $ (i, n-1) $.

So cleverly constructed a grouping method, such that each side have appeared once and only once, the problem is solved.

Guess you like

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