Codeforces Round #847 (Div. 3) AF Blue Fame

Want to get the blue name, 1414 points before the game, the target blue name.
update updateu p d a t e ranked57 5757

A. Polycarp and the Day of Pi
The meaning of the question is to give you a number to judge whether the number matches the first 30 digits of pi.
The train of thought found that the sample has a number with a length of 30, ctrl + cv ctrl + cvctrl+C v , a violent judgment is enough.
the code

B. Taisia ​​and Dice
question meaning for you nnn dice, currentnThe total score of n dice issss , remove a dice with the highest score and the score isttt , construct thisnnn dice score, score <= 6,n <= 50 n <= 50n<=50 .
The idea is easy to find that the maximum value issss - t t t , now judge whether all the dice have the maximum score and can formsss , then violently assign the score to the remainingn − 1 n-1n1 dice.
the code

C. Premutation
question means to give you a permutation array ppp , then gives younnn arrays, each array is arrangedppp removes theiii itempi p_ipiAfter the array, pass this nnn array reverse derivation arrayppp ( 3 ≤ n ≤ 100 ) (3≤n≤100) (3n100 ) , the subscripts of the removed items are not guaranteed to be in order, but are guaranteed to be an arrangement.

insert image description here
Ideas to count each value in nnThe sum of subscripts that appear in n arrays can be sorted.
the code

D. Matryoshkas
title means to give you an array ai a_iai, we call the continuous sequence as the sequence is composed of continuous numbers, ask you how many continuous sequences this array can be composed of, n <= 2 e 5 n <= 2e5n<=2 e 5 .
sample

6
2 2 3 4 3 1
2

Sample analysis: can be decomposed into [ 1 , 2 , 3 , 4 ] [1 , 2 , 3 , 4][1,2,3,4] , [ 2 , 3 ] [2 , 3] [2,3 ] .
Violent simulation of the idea is enough, enumerate all the first items from small to large, and intercept the longest continuous sequence, and count the number.
the code

E. Vlad and a Pair of Numbers
The meaning of the question is whether you have two numbers, given a xxx , fullx = = ( a + b ) / 2 = = ( ax == (a + b) / 2 == (ax==(a+b)/2==(a^ b ) b) b ) , it is not rounding down, it is divisible by 2, and the range of values ​​isa, b <= 2 2 a, b <= 2^2ab<=22 9 ^9 9 .
Consider( a + b ) / 2 = = ( a (a + b) / 2 == (a(a+b)/2==(a ^ b ) b) b ) When this formula is established, consider thekkthk bits, if thekkthThe k bit is 1, we found that only one is 1 to ensure that the XOR is 1, to satisfy( a + b ) / 2 (a + b) / 2(a+b ) /2 is 1, plus and then divided by 2 requires two 1s to ensure thekkthThe k bit is 1, so how do we construct a 1? We can consider using the low bit 1 to construct a high bit 1, which requires that the low bit cannot be 0, and the low bit can only be two 1, and then construct a High 1, thekkthThe k bit is 0, and it can be seen as 0 by default.
the code

do eee took only half an hour,A − E AEAE is more partialto edu eduThe simple questions of e d u , most noobs can dod, ed, ed,Part e , those with stronger ability can be placed indiv 3 div3d i v 3 can get a good ranking only by making the first five moves, which is a good starting point.

F. Timofey and Black-White Tree
means to give you a size of nnThe tree of n , initiallyc 0 c0c 0 point is black, then executemmm operations, each operation dyes a point black, and asks you the minimum distance between all pairs of black points after each coloring.
During the game, I used a tree section + line segment tree method to do it. The idea is to consider maintaining two relationships. One is to add this point, and the answer is between this newly added point and the black point of the subtree where this point is located. The shortest distance, use dfs to maintain line segment tree maintenance. The second is to consider the impact of not being in this subtree. The answer must bed [ u ] + d [ v ] − 2 ∗ d [ lca ( u , v ) ] d[u] + d[v] - 2 * d[ lca(u , v)]d[u]+d[v]2d[lca(u,v )] , we maintain the followingd [ v ] − 2 ∗ d [ lca ( u , v ) ] d[v] - 2 * d[lca(u,v)]d[v]2d[lca(u,v )] , we findlca ( u , v ) lca(u , v)lca(u,v ) must beuuancestors of u , we consider maintainingvvAll paths from node v to the root ared [ v ] − 2 d [ t ] d[v] - 2d[t]d[v]2 d [ t ] maximum value,ttt isvvancestor of v , thenuuu ,vvv l c a lca l c a must be the intersection of the maximum depth of the two paths to the root.
Knowing after the game that there is a simplernsqrt ( n ) nsqrt(n)The practice of n s q r t ( n ) is adfs dfsThe very useful violence of df s will be updated in the follow-up.
the code

Today's div3's F is a wonderful question for human beings, which killed a mindless konjac like me.

U p d a t i n g Updating Updating
insert image description here

Guess you like

Origin blog.csdn.net/qq_52358098/article/details/128783430