Miscellaneous questions mouth Hu

$ Bitwise \ Xor $: Given a length of n-$ $ $ A $ sequence of integers and an integer K $ $, $ A request sequence number with a $ pairwise XOR value equals $ k $. $ n \ leq 3e5, k < 2 ^ {60} $

Solution: find the minimum value of the exclusive OR twenty-two must be sorted adjacent two numbers, the first sort $ A $, provided f [i] indicates the number of sequence ending i. Optimization DP $ $ $ a $ Trie tree, each node maintains and subtrees of the values ​​$ f $ $ $ Trie, according to the current bit should be greater than $ X $ $ $ 0 or $ 1 $ recursively descend. $ F [i] = query (a [i], x) + 1 $. Plus his own clusters alone. $ O (nlogk) $

 

The MOD $ \ $ Problem: T inquiry group, n-given $ $, seeking $ \ sum \ limits_ {i = 1} ^ {n} n \ mod \ i $. $ T \ leq 1e6,1 \ leq n \ leq 1e7 $

Interpretations: $ \ sum \ limits_ {i = 1} ^ {n} n \ mod \ i = \ sum \ limits_ {i = 1} ^ {n} n- \ left \ lfloor \ frac {n} {i} \ right \ rfloor * i = n ^ 2- \ sum \ limits_ {i = 1} ^ {n} \ left \ lfloor \ frac {n} {i} \ right \ rfloor * i $. There $ \ sum \ limits_ {i = 1} ^ {n} \ left \ lfloor \ frac {n} {i} \ right \ rfloor * i = \ sum \ limits_ {i = 1} ^ {n} = d ( i) \ \ \ \ d (i) $ represents about $ I $ and. Wire sieve and seeking to prefix. $ O (T + n) $

 

Square string: define square string if and only if the string has a non-empty and it can be made with two identical series. Preceded by a length of $ n-$ string $ S $, random remove a non-empty strings, if this substring no leading $ 0 $ and squared string, contribute to the value of the string, or contribute to the $ 0 $, seeking extracted sub expected contribution of the string. $ 1 \ leq s [i] \ leq 9 $, $ n \ leq 5e5 $.

Solution: There is a classic routines: interpolation point method. DETAILED enumeration squared length of the string is $ 2 * len $, then every string of the original $ a $ len a key is inserted, the string will be squared up across two key points. Two key points enumerated strings three sections, the first two requirements longest common suffix strings, the longest common prefix after two strings, strings found in the square may be left in a point $ [l, r] $ interval slide (recommended drawing understand). Preprocessing the $ f [i] = f [i-1] * 10 + s [i] $, then the $ [i, j] $ configuration number is $ f [j] -f [i-1] * 10 ^ {j-i + 1} $, and processing a prefix. Then the string can be easily obtained the first half of the square contribution $ sum $, then the final contribution to $ sum * 10 ^ {len} + sum $. $ 0 $ case preamble of: when the process if f $ s [i + 1] == 0 $, then $ f [i] = 0 $. Because it is the first half of the square of the processing sequence, $ i + 1 $ then equal to the beginning of the string, the f value is set directly to $ 0 $ would not taken into account. Complexity harmonic series $ O (nlnn) $

 

Several mathematical probability of the entire entrance to the formula:

$ P (A | B) $ $ A $ represents the probability of at $ B $ occurs, $ P (AB) $ and $ A $ denotes the probability $ B $ simultaneously.

Total probability formula: Suppose $ B_1, B_2 ... B_k $ is a basic split event, the $ P (A) = \ sum \ limits_ {i = 1} {k} P (A | B_i) * P (B_i ) $

Conditional probability: $ P (A | B) = \ frac {P (AB)} {P (B)} $

Bayesian formula: $ P (A | B) = \ frac {P (AB)} {P (B)} = \ frac {P (B | A) P (A)} {P (B)} $

 

$ Conjugate $: There are $ n $ heap of stones, the first $ i $ heap of stones there is a $ a_i $, and so the probability of randomly selected each time a stone put it in the pile of lost it all, seeking hope the first $ 1 $ heap after how many times stones are dropped. $ n \ leq 1e6, a_i \ leq 1e9 $

Solution: desired linearity. Consider the first $ I $ stones piled $ (i> 1) $ probability stones thrown away before the first stack is being lost $ \ frac {a [i]} {a [i] + a [1]} $, of the number of answers contribution to $ 1 $, so $ ans = \ sum \ limits_ {i = 2} ^ {n} \ frac {a [i]} {a [i] + a [1]} \ \ + 1 $. Plus one that lost the first $ a_1 $. $ O (n) $

 

Lakers: Number of $ 1 ~ n $, after each randomly select a number has not been omitted $ x $, all multiples including himself deleting, find the desired number of times all numbers have been deleted. $ 1 \ leq n \ leq 1e9 $

Solution: as above, consider the linearity desired. For the number of $ x $, their probability of being deleted is $ \ frac {1} {d (x)} $. Puncturing each time answers contribution $ $ 1, the $ ans = \ sum \ limits_ {i = 1} ^ {n} \ frac {1} {d (i)} $. $ N $ large, with a $ min25 $ sieve (I will not so terrible).

 

$ Game \ with \ Marbles $: bag contains red balls $ R & lt $, $ G $ a $ B $ green ball and a basketball. Each turn probability randomly taken from a ball bag. If the red ball, to throw away; if it is green ball or basketball, they put in the bag. The current known just come up with the first $ K $ a basketball, after several rounds of demand expectations. $ 1 \ leq R, G, B, K \ leq 1e9 $

Solution to a problem :( fully aware of just how idiot on probability, not quite understand, super sensual, may be wrong) Xia Xie: expected number of rounds won $ = $ expected number of balls $ = $ number of red balls expect $ $ + $ + $ number basketball expect the number of green balls expectations. The desired linearity can find the sum, respectively. Come up with $ K $ a basketball, it is expected to come up with $ K $ a basketball. Consider before each touched a basketball touched expected to touch a few green ball, this time can not be considered a red ball (red to take took a no impact), it lists the equation $ E = \ frac {G} { B + G} * (E + 1) $, solve for $ E = \ frac {G} {B} $. Therefore, the total desired touch $ \ frac {KG} {B } $ a green ball. Consider took out his red ball for each probability, found very good count, so in turn, find the probability of each ball has not been touched: also a basketball can only consider all this and a red ball, red ball It has not been take, so this $ K $ times are taking basketball. Probability of a basketball get $ \ frac {B} {B + 1} $, $ K $ times the probability is no palpable red ball as $ (\ frac {B} { B + 1}) ^ K $. Therefore, the probability of a red ball being touched is $ 1 - (\ frac {B } {B + 1}) ^ K $. Each red balls are independent, touch the red ball expectations $ (1 - (\ frac { B} {B + 1}) ^ K) * R $. (Deep understanding, could be wrong ...)

 

: $ UOJ $ # $ 299 $ Games probability 1 $ innings small $ R $ win, i-innings small $ R $ winning - $ N $ Board games, given the probability of the first game of two people were winning, when the first $ i to $ P_i $; when the first $ i-1 $ $ B $ winning innings small, the probability of the $ i $ $ B $ winning small office for $ Q_i $. $ M $ secondary dynamically insert or remove some known results of the competition, find the expected number of General Administration of winning $ $ R. $ 1 \ leq N, M \ leq 2e5 $

Solution: Linear expectations of $ + $ Bayesian formula. Each game must only be related to the results of both sides have been identified. This carved out of a number of intervals, $ M $ revision corresponds to the two sections merge into one section or the two sections. Suppose the current $ X $ have been identified on both sides of the event is $ A, B $. The conditional probability, there is $ P (X | (A \ bigcap B)) = \ frac {P (X \ bigcap A \ bigcap B)} {P (A \ bigcap B)} = \ frac {P ((X \ bigcap B) | A) P (A)} {P (B | A) * P (A)} = \ frac {P ((X \ bigcap B) | A)} {P (B | A)} $. Then segment tree maintenance matrix multiplication maintain the numerator and denominator.

 

$ AGC035D $: length n $ A $ sequence, wherein each successive three may be selected, followed by $ a, b, c $, to replace $ a + b $, $ b + c $ two. Minimization and the rest of the final two numbers. $ 2 \ leq n \ leq 1e9 $
Solution: First title in operation can also be seen as a select number, added his weight around on two, and took him to delete. Finally, the answer is found to forget each number several times. Consider this process backwards and found $ 1, the $ count on only a certain position n forget $ 1 $ times, the penultimate deleted forget the number of times each number twice ... so calculated is left of the first a number of times after he deleted the first $ $ + the right number of times after he deleted. Consider memory search. $ Solve (l, r, cntl, cntr) $ representing the interval $ (l, r) $, $ l $ $ CNTL times calculated $, $ r $ $ CNTR $ calculation times. $ F [l] [r] [cntl] [cntr] = \ min \ limits_ {l <i <r} {solve (l, i, cntl, cntl + cntr) + sovle (i, r, cntl + cntr, cntr)} $.
 
$ CF765F $: Given a sequence of length n-$ a $, $ m $ times have asked each time a given interval $ [l, r] $, seeking $ \ min \ limits_ {l \ leq i <j \ leq r} {| A_i-A_j |} $. $ n \ leq 2e5, m \ leq 3e5 $

Solution: tree line. This problem seems to have seen several times, or the original title? Can not remember. Does not require compulsory online, offline, down by $ r $ sorting, dynamic maintenance of the current point when the answer is right point with tree line. If the absolute value hard to deal with, so only consider the $ j <i $ and $ a [j] \ geq a [i] $ , and another case like it again upside down. Now, we impact from the right end of $ a [i-1] $ move $ a [i] $, consider $ a [i] $ is added to bring. Find the left of the first $ i $ greater than $ a [i] $ position $ pos $, $ pos $ updated answer location. For $ k <pos $, if $ a [k] \ geq a [pos] $, then the answer and between $ k $ $ $ POS must answer preferably between $ k $ and $ I $ ratio, and can take to $ k $, then we must be able to take $ pos $. For $ a [k] <a [ pos] $, set $ mid = (a [i] + a [pos]) >> 1 $, if $ a [k]> mid $ , $ k $ and $ $ POS the answer will not control the reverse calculation of time; the situation so we need only consider the $ a [k] \ leq mid $ each time interval length will be $ / $ 2, has been handling down just fine. Complexity $ O (nlognloga_i) $

 

$ operation $: seems to have done? Good block Dafa.

 

 

 

 

Guess you like

Origin www.cnblogs.com/jrf123/p/12651469.html