codeforces 833(div2) B to D
cf833 div2
B.Diverse Substrings
statement
Find the number of substrings of \(s\) consists of only \('0' \to '9'\) that satisfies max{alpha occurrences} \(\leq\) s.size( ).
solution
The most significant point is the length of s will not exceed 10*10 = 100. So it's available to let \(i\) be the start position and check answer in next \(100\) numbers and break when the condition fails to satisfy.
code link
https://codeforces.com/contest/1748/submission/180703499
C.Zero-Sum Prefixes
statement
Given an array \(a_n\) consists of integers in range of \([-10 ^ 9, 10 ^ 9]\), in every operation you can choose a position \(i\) that \(a_i = 0\), and change \(a_i\) to an arbitrary integer. Maxizize the number of \(x\) that satisfies:
solution
Notice that every two \('0'\) is independent, which means every time you're going to change the value of \(a_i\), you only need to consider how the new value will influence the number who's index is between \([i + 1, next \, zero's \,pos]\).
So in every operation you only need to maximize present answer, thus we take strategy like finding out the most occurances prefix sum between \([i + 1, next \, zero's \,pos)\), and add it to the final result.
code link
https://codeforces.com/contest/1748/submission/180705816
D.ConstructOR
statement
Given integer \(a, b, d\), find any possible \(x(0 \leq x \leq 2 ^ {60})\) that satisfies:
solution
Given the features of bitwise OR operation
, we can simplify the description of the question as find a x which not only is a multiple of d but also x mod a|b = 0.
In other words, \(x\) is constructed by \(d\) in binary and the binary form of \(a|b\) is a subset of \(x's\).
So we can try to construct the \(x\) in binary form from low position to high position. When the \(i\)-\(th\) value is \(1\) in \(a|b_{(2)}\), we can add a \(d's\) multiple using ‘<<’ operation that can guarantee the value in current position is same as \(a|b_{(2)}\) \('s\).