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.

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:

\[(\sum_{j = 1}^{x}a_j) = 0 \]

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.

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:

\[d \mod a | x = 0 \\ d \mod b | x = 0 \]

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\).

posted @ 2022-11-18 00:23  BeyondLimits  阅读(31)  评论(0编辑  收藏  举报