Excited to share that I participated in #CodeChef STARTERS145A (division 1), got 4 problems and was 35th on official standings.
Following are some high level ideas for the problems I solved, if anyone finds it useful.
A. Make Bob Win (https://lnkd.in/dVz6q75x)
Observe that blocks of 1 have to be strictly greater than blocks of 0, for bob to always win because bob can just make sure this constraint hold after moves by both player.
Otherwise alice can force the same constraint and bob will lose.
B. Square String (https://lnkd.in/dgPFgXQN)
For a single index i, having last unequal character at some j position, contribution to answer in such case will be 2 ^ (n - i - j - 1) * (i - j) ^ 2.
Notice that this function can be precalculated for each value of i - j and then we can add prefix sums to our final answer.
C. Beautiful Array (https://lnkd.in/dEBZ7rSs)
First try to greedily build the answer for each query bit by bit starting from the highest bit.
For some bit either it's already present in all elements of array or it's missing at some places, in case of missing, we can add back this bit to missing positions if and only if total number of consecutive blocks of such positions <= k.
Also once we add some bit using operations at certain intervals, we are now restricted and cannot perform any more operations for any other bit, because that will break the greedily taken bit earlier and thus reducing the answer.
This when implemented with some precalculations will be enough.
D. Querified (https://lnkd.in/dGV6sXyy)
First gcd(v, u) has to be one of the divisors of u, so for each u we can iterate over divisors of it and see if some multiple of that divisor is in it's subtree.
Problem will be easier if we kind of start putting values from 1 to N, hence when we are calculating for some value we know for sure we only have values lower than this one, hence no longer to worry about the constraint v < u.
Only issue when iterating value-wise(1 to N) is how to know for each divisors of u, that we have some multiple of it in it's subtree.
I used Euler tour for this which essentially maps subtrees to a range [L, R] so we can just use sets to track indexes of found elements and then check if desired multiple is in current range or not.
Помощник бухгалтера – Автошкола
6dIt's good ,