Блог пользователя Fakewave

Автор Fakewave, 4 месяца назад, По-русски

Спасибо за участие в раунде! Мы надеемся, что вам понравились задачи.

2234A - Евклид, последовательность, два числа

Идея: FairyWinx

Подсказка 1
Подсказка 2
Решение
Код (Python)
Код (C++)
Оцените задачу

2234B - Палиндром, двенадцать, два слагаемых

Идея: Fakewave

Решение
Код (Python)
Код (C++)
Оцените задачу

2234C - Сосуды, высоты, две версии (простая версия)

Идея: yanb0

Подсказка
Решение
Код (Python)
Код (C++)
Оцените задачу

2234D - Ксор, выражение, два бинарных числа

Идея: Fakewave

Подсказка 1.1
Подсказка 1.2
Подсказка 1.3
Решение 1
Код (C++) к решению 1
Подсказка 2.1
Подсказка 2.2
Подсказка 2.3
Подсказка 2.4
Решение 2
Код (C++) к решению 2
Оцените задачу

2234E - Влад, Миша, два массива

Идея: Fakewave

Подсказка 1.1
Подсказка 1.2
Решение 1 (yanb0)
Код (C++)
Решение 2 (_Crimson_)
Оцените задачу

2234F - Сосуды, высоты, две версии (сложная версия)

Идея: yanb0

Подсказка 1
Подсказка 2
Подсказка 3
Решение
Код (Python)
Код (C++)
Оцените задачу

2234G - Полоска, фишка, два игрока

Идея: yanb0

Подсказка 1
Ответ к подсказке 1
Подсказка 2
Ответ к подсказке 2
Подсказка 3
Подсказка 4
Решение
Код (C++)
Оцените задачу
Разбор задач Codeforces Round 1102 (Div. 2)
  • Проголосовать: нравится
  • +124
  • Проголосовать: не нравится

»
4 месяца назад, скрыть # |
Rev. 4  
Проголосовать: нравится +21 Проголосовать: не нравится

A fun fact that CCO '26 P2 is similar to problem E :) In that question you are supposed to output a construction instead of finding the total possible permutations.

»
4 месяца назад, скрыть # |
 
Проголосовать: нравится +30 Проголосовать: не нравится

an O(n) solution for E: 377668463

The idea is that you can find the nearest smaller element to the left and right of each position using a monotonic stack. These determine the cartesian tree corresponding to all valid permutations

  • »
    »
    4 месяца назад, скрыть # ^ |
     
    Проголосовать: нравится +16 Проголосовать: не нравится

    Thank you! Our testers also pointed out that there is an $$$\mathcal{O}(n)$$$ solution (that is one of the reasons for the decision of making the problem have the index E), and we are planning to add it to the tutorial soon.

  • »
    »
    4 месяца назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится

    I did the same, although implementation ended up easier maintaining only two arrays l and r of nearest bigger element to the left and to the right (without the stacks): 377671821

»
4 месяца назад, скрыть # |
Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

I took a different approach to E, filling in numbers top-down rather than from left/right ends. Idea is to start with a set of intervals $$$\left\lbrace[i,i] : a[i]=1\right\rbrace$$$ (which must be the local maxima) and trivial intervals between adjacent elements. Repeatedly consider the endpoints of the intervals (only needing to reconsider a point when it's the endpoint of a new interval). For each interval maintain the total number of possible orderings, and when we join two intervals together, the number of orderings of the new one is $$$\text{left_orderings}*\text{right_orderings}*\binom{\text{left_size}+\text{right_size}}{\text{left_size}}$$$; continue until we can't proceed or everything has been joined into one interval. I did this with DSU for $$$O(n \alpha(n))$$$ but it can straightforwardly be done in $$$O(n)$$$ using linked lists.

»
4 месяца назад, скрыть # |
 
Проголосовать: нравится +14 Проголосовать: не нравится

there is some writing mistake in E's solution :
let's check this condition for the indices [l,r] in the following order: l,r,l+1,r−1,r+2,r−2,… . We will prove that with this optimization, the algorithm will run in O(n^2) time.
should be
let's check this condition for the indices [l,r] in the following order: l,r,l+1,r−1,l+2,r−2,… . We will prove that with this optimization, the algorithm will run in O(nlogn) time.

»
4 месяца назад, скрыть # |
 
Проголосовать: нравится +3 Проголосовать: не нравится

Man htf can one come with the optimization done in E for a O(n logn) solution as proving this things is a different things but coming with them is not and this is the first time I am seeing such a optimization . Figured out the whole idea for E but didn't knew how to optimize it during the contest btw

»
4 месяца назад, скрыть # |
 
Проголосовать: нравится +1 Проголосовать: не нравится

Could someone elaborate complexity proof in E?

  • »
    »
    4 месяца назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится

    You can refer to my stream for proof here

  • »
    »
    4 месяца назад, скрыть # ^ |
     
    Проголосовать: нравится +3 Проголосовать: не нравится

    You initially have $$$1$$$ segment of indices of size $$$n$$$, and every time you split a segment of size $$$x$$$ into segments of sizes $$$k$$$ and $$$x-k$$$, you do $$$O(k)$$$ work. Let's "charge" that work to the first $$$k$$$ elements of a segment. Then observe that every time you charge an element, the new segment it is in is at most size $$$\lfloor\frac{x}{2}\rfloor$$$. Therefore each element can be charged at most $$$log_2(n)$$$ times, which gives a total bound of $$$nlog_2(n)$$$.

  • »
    »
    4 месяца назад, скрыть # ^ |
    Rev. 4  
    Проголосовать: нравится +8 Проголосовать: не нравится

    Let's say the number of operations to solve subarray $$$(l, r)$$$ of size $$$s = r-l$$$ is $$$F(s)$$$. If we find the minimum in this subarray at index $$$i = l+k$$$, The naive solution takes $$$k$$$ steps to find $$$i$$$ then solve subarrays of size about $$$k$$$ and $$$s-k$$$ respectively. This gives the recurrence $$$F(s) = k + F(k) + F(s-k)$$$ for some $$$k \in [0, s]$$$.

    The worst case is $$$F(k) = O(k^2)$$$ which happens when $$$k$$$ always equals $$$s$$$, corresponding to a decreasing permutation.

    The optimized solution just loops from both sides at the same time, which reduces the number of steps to find the $$$i$$$ from $$$k$$$ to $$$\min(k, s-k)$$$. The new recurrence is $$$F(s) = \min(k, s-k) + F(k) + F(s-k)$$$.

    Letting $$$a = \min(k, s-k)$$$, we get $$$F(s) \leq a + 2F(a)$$$ for some $$$a \in [0, \frac{s}{2}]$$$. Because the the function $$$a + 2F(a)$$$ is clearly increasing, the worst case will happen when $$$a$$$ always equals $$$\frac{s}{2}$$$.

    Let $$$G(s) = \frac{F(s)}{s}$$$, dividing by s on both sides and plugging in the worst case,

    $$$\frac{F(s)}{s} \leq 2\frac{F(s/2)}{s} + \frac{1}{2}$$$
    $$$G(s) \leq G(\frac{s}{2}) + \frac{1}{2} \leq G(\frac{s}{4}) + 1 \leq G(\frac{s}{8}) + \frac{3}{2} \leq \dots \leq G(\frac{s}{2^k}) + \frac{k}{2}$$$
    $$$G(s) \leq G(\frac{s}{2^{\log_2s}}) + \frac{\log_2s}{2}$$$
    $$$F(s) \leq sG(s) = O(s \log_2s)$$$
    • »
      »
      »
      3 месяца назад, скрыть # ^ |
       
      Проголосовать: нравится +3 Проголосовать: не нравится

      I think there might be an issue with the step

      $$$F(s)=a+F(k)+F(s-k), \qquad a=\min(k,s-k)$$$

      followed by

      $$$F(s)\le a+2F(a).$$$

      Since

      $$$a\le k$$$

      and

      $$$a\le s-k,$$$

      assuming F(x) is non-decreasing we have

      $$$F(k)\ge F(a), \qquad F(s-k)\ge F(a).$$$

      Therefore

      $$$F(s)=a+F(k)+F(s-k)\ge a+2F(a),$$$

      not

      $$$F(s)\le a+2F(a).$$$

      Could you clarify how this inequality is obtained, or if there is an additional argument that I'm missing?

  • »
    »
    4 месяца назад, скрыть # ^ |
     
    Проголосовать: нравится +6 Проголосовать: не нравится
    ...
    

    $$$T(n)\le\alpha\min(k, n - k) + T(k) + T(n - k)$$$ for some $$$\alpha$$$.

    Assume by induction $$$T(i) \le C\cdot n\log n$$$ for some $$$C$$$ and all $$$i \lt n$$$, then :

    $$$\begin{align} T(n)&\le\alpha\min(k, n - k) + Ck\log k + C(n-k)\log(n-k)\\ T(n)&\le\alpha\min(k, n - k) + Ck\log k + C(n-k)\log(n-k) + Ck\log n - Ck\log n + C(n-k)\log n - C(n-k)\log n\\ T(n)&\le\alpha\min(k, n - k) + Ck(\log k - \log n) + C(n-k)(\log(n-k) - \log n) + \left(Ck\log n + C(n-k)\log n\right)\\ T(n)&\le\alpha\min(k, n - k) - Ck\left(\log\frac n k\right) - C(n-k)\left(\log\frac n{n-k}\right) + Cn\log n\\ \end{align}$$$

    Now by symmetry assume $$$k \lt \frac n 2$$$, you get $$$\frac{n}{k}\ge2$$$ and since $$$\frac{n}{n-k}\ge 1$$$ :

    $$$\begin{align} T(n)&\le\alpha k - Ck(\log 2) + Cn\log n\\ T(n)&\le k(\alpha - C(\log 2)) + Cn\log n\\ \end{align}$$$

    So it suffices to take $$$C \ge \dfrac\alpha{\log 2}$$$ to conclude.

»
4 месяца назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

My detailed 3 hour 15 minute detailed video editorial is now available here.

»
4 месяца назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Can someone point out why I keep gettting TLE in probleme E here 377706411 ?

I thought in a similar way to the editorial and I implemented the O(nlog(n)) way, with the tiny difference that I computed the (i−l+1)(r−i+1) by adding a number in every iteration, but I don't think it influences the execution time.

Thanks in advance!

»
4 месяца назад, скрыть # |
 
Проголосовать: нравится +6 Проголосовать: не нравится

For D one can do a braindead memoized recursion. We only need to notice that there are 3 types of numbers: $$$a$$$, $$$b$$$, $$$a \oplus b$$$. Let's call them types: 1, 2, 3.

Let the answer for the problem be $$$f(a, b, k)$$$. Let $$$g(x)$$$ be the product of the number of set bits and the number of zero bits. What is the transition?

$$$f(a, b, k) = f(a, a \oplus b, k - 1) + f(a \oplus b, b, k - 1) - g(a \oplus b)$$$.

That is, in the types notation we have:

$$$f(1, 2, k) = f(1, 3, k - 1) + f(3, 2, k - 1) - g(3)$$$

Now, note that $$$f(t_1, t_2, k') = f(t_2, t_1, k')$$$, so we can only store the answer for the triplets $$$(t_1, t_2, k')$$$ with $$$t_1 \lt t_2$$$. One can use map to conveniently store such states.

For each $$$k' \le k$$$ we need to store at most $$$3$$$ states, so the total number of recursion calls is at most $$$3k$$$.

»
4 месяца назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Can someone explain problem C? I don't mean the solution, just the problem, I don't understand it...

  • »
    »
    4 месяца назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится

    Imagine you have $$$n$$$ containers (cylindrical and with the same area at the bottom) arranged in a circle with adjacent containers being connected by a tube (the tube's connection is at the same height in both containers). When you add water to a container, the water level rises, but if it exceeds the level of one of the tubes, then the water will start flowing through the tube. That means that if you keep filling the tube, then eventually the water level of both containers will be the same (assuming that the water doesn't escape to another container). The formalization just says that when the water level of at least one of the containers is above the tube that connects them, then their water levels must be equal because otherwise water would flow from the container of higher volume to the one of lower volume.

    The task is to find a way to add water to the containers so that no water overflows into the container $$$i$$$ while maximizing the total amount of water in all the containers (the actual task is to find the amount of water not the way to fill the containers).

    Is this explanation clear or is there a doubt I didn't address?

»
4 месяца назад, скрыть # |
 
Проголосовать: нравится +11 Проголосовать: не нравится

Good compitition! Short code length of DEF made me became Master lol.

»
4 месяца назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

In editorial for Problem C, what do you mean by i != l? What is l here?

»
4 месяца назад, скрыть # |
Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

there is a sparse table + binary search approach to F too . that felt more intuitive to me . we can rotate the array, to get the peak at the end . each particular value will contribute to some elements only(that too will be in a contiguous segment), then we can use difference array and finally get the answer..

code. used gemini for the code during upsolving , cuz i fumbled implementation.

»
4 месяца назад, скрыть # |
Rev. 2  
Проголосовать: нравится +3 Проголосовать: не нравится

for E you can notice that the range of the first element always should be $$$[1, a_1]$$$, then then from that, you can find the range of the $$$a_1 + 1$$$-th element with a division as the length should be $$$\frac{a_{a_1 + 1}}{{a_1 + 1}}$$$ and from that you find the range corresponding to the $$$\frac{a_{a_1 + 1}}{{a_1 + 1}} + a_1 + 1$$$-th element and so on..., basically you can find all of the right parents of element 1 until the root (the element with the range $$$[1, n]$$$), we then mark everyone, and then do the same process for of $$$2, 3, ... , n$$$ each time you repeat the process until you reach the root or a marked element (for $$$2$$$ for example you can find all right parent until you reach some range that starts with $$$1$$$ which has been marked before). to satisfy all conditions for each division the numerator should be divisible by the denominator and also you should never go out of range, also after that you should check that the ranges you found satisfy the condition: "any two segments either dont intersect at all or one is contained in the other", you can sort the ranges in $$$O(n)$$$ or $$$O(n \log n)$$$.

$$$O(n)$$$ submission: 377742663

»
4 месяца назад, скрыть # |
Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

In Solution 2 of problem D, $$$F(l,A,B)=F(l−1,A,A⊕B)+F(l−1,A⊕B,B)$$$+[product of the $$$0$$$ and $$$1$$$ bit counts for $$$A⊕B$$$] should be replaced by $$$F(l,A,B)=F(l−1,A,A⊕B)+F(l−1,A⊕B,B)$$$ $$$\bf{-}$$$ [product of the $$$0$$$ and $$$1$$$ bit counts for $$$A⊕B$$$ ]. I think, it was typo. Also, the time complexity given is wrong I guess because for each $$$k$$$ we can have at max $$$6$$$ permutations of $$$A, B, C$$$ so, $$$6k$$$ states total. And, we need $$$O(\log k)$$$ time to calculate each state. Hence, time complexity should be $$$O(n + k\log k)$$$

»
4 месяца назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Guys, i wonder if the technique used in problem E can be applied to other dnc like technique? I meant like what if instead of a permutation or an array, we are given the permutation of tree nodes? Can the same technique apply?

»
4 месяца назад, скрыть # |
 
Проголосовать: нравится +3 Проголосовать: не нравится

The formulation for problem C is too vague imo. On a second read this problem is very doable, but essentially it should be very intuitive.

  1. It is not immediately readable how the sequences h_i and w_i relate. In particular, h_i represents the height of the connection between vessel i and vessel (i mod n) + 1 (so, the next vessel in the circle), but this is not emphasized clearly enough. The term “partition” in the input description also feels a bit vague. “Connection” or something similar would fit better here.

  2. This causes the formal definition to feel difficult, when it should be trivial to understand. A better formulation for this would imo be:

Between vessel i and vessel (i mod n) + 1, there is a connection at height h_i. If the water level in either of the two vessels rises strictly above this connection height, then the two vessels must have equal water levels.

  1. Also, the output explanation could be made clearer by saying that for each vessel l, we need to output the maximum possible value of w_1 + w_2 + ... + w_n, over all good arrays satisfying w_l = 0.

So, for the plebs like me solving problem C:

You have a circle of water tanks, and they are connected to their neighbours with tubes. The heights of those tubes are given by the array h, where h_i is the height of the connection between vessel i and vessel (i mod n) + 1. So h_1 connects vessels 1 and 2, h_2 connects vessels 2 and 3, ..., and h_n connects vessel n back to vessel 1, completing the circle.

The array w describes the water level in each vessel. The condition says: if the water level in either of two neighboring vessels is strictly above the height of the tube between them, then those two vessels must have the same water level.

For each vessel l, let G_l be the set of all good arrays w satisfying w_l = 0, meaning vessel l remains empty.

For each G_l, we want the maximum possible total amount of water across all vessels. Formally, this is the maximum possible value of w_1 + w_2 + ... + w_n, over all arrays in G_l. Let this maximum value be denoted by m_l.

Your goal is to output the sequence:

m_1 m_2 m_3 ... m_n

Note Consider the first test case, where n = 4 and h = [1, 2, 3, 4].

To keep vessel 1 empty, the array w = [0, 0, 1, 0] is a good array in G_1, because no pair of neighboring vessels has a water level strictly above the height of the connection between them. Its total volume is 1.

However, this array is clearly not maximal. A maximal array in G_1 is w = [0, 1, 2, 3], with a total volume of 6. Therefore, m_1 = 6.

So w = [0, 1, 2, 3] is a good array with sum 6, and it can be shown that no array in G_1 has a larger sum.

Similarly:

  • to keep vessel 2 empty, one maximal good array is w = [1, 0, 2, 3], thus with a m_2 of 6;
  • to keep vessel 3 empty, one maximal good array is w = [2, 2, 0, 3], thus with a m_3 of 7;
  • to keep vessel 4 empty, one maximal good array is w = [3, 3, 3, 0], thus with a m_4 of 9.

Therefore, the final output is constructed from the indexed maximum good values m_1 m_2 m_3 m_4:

6 6 7 9

»
4 месяца назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Problem C had a very confusing explanation, that could use some work. The problem itself wasn't bad tho

»
4 месяца назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится
Stupid solution for D
»
4 месяца назад, скрыть # |
 
Проголосовать: нравится +8 Проголосовать: не нравится

Induction proof for $$$n \log n$$$ in E:

We spend $$$ck$$$ time iterating through the array to then recurse on problem sizes $$$n-k$$$, $$$k$$$. (I'm going to avoid big-O as much as possible because you can make errors with it easily because you might absorb constants too much and actually end up with an extra log or even exponential factor.) Suppose that by induction we can solve the problem size $$$k$$$ in $$$C k \log_2 k$$$ and $$$n-k$$$ in $$$C(n-k) \log_2 (n-k)$$$.

Then

$$$T(n) = T(n-k) + T(k) + ck,$$$

$$$T(n) \le C(n-k) \log_2(n) + Ck \log_2(k) + ck.$$$

We know that $$$k \le \frac{n}{2}$$$, so $$$\log_2 k$$$ is at most $$$\log_2(n) - 1$$$:

$$$T(n) \le C(n-k) \log_2(n) + Ck (\log_2(n) - 1) + ck,$$$

$$$T(n) \le Cn \log_2 n - Ck + ck.$$$

Now we see that $$$T(n) \le Cn \log_2 n$$$, as desired, if $$$C \ge c$$$.

»
4 месяца назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

I solved D without the observation that all numbers must be A, B or A^B.

For a fixed bitset t, #1 * #0 = $$$\sum_{i=1}^n\sum_{j=i+1}^nt[i] \oplus t[j]$$$.

Answer will be $$$\sum_{l=1}^{2^k+1}\sum_{i=1}^n\sum_{j=i+1}^na[l][i] \oplus a[l][j]=\sum_{i=1}^n\sum_{j=i+1}^n\sum_{l=1}^{2^k+1}a[l][i] \oplus a[l][j]$$$. $$$a[l][i]$$$ and $$$a[l][j]$$$ are dependent only on $$$a[1][i], a[2^k+1][i], a[1][j], a[2^k+1][j]$$$. There are only 16 combinations of values of $$$a[1][i], a[2^k+1][i], a[1][j], a[2^k+1][j]$$$, we can group (i,j) according to these values and calculate the answer. For a fixed quadruple we use dp given in the second solution, but each l will have 16 states at most as both A <= 3 and B <= 3 and we can do it explicitly.

»
4 месяца назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

E is beautiful, that optimization technique to show that search cost changes from O(n)->O(k) and now depends on smaller child which keeps halving because of the way we are iterating is very clever.

»
3 месяца назад, скрыть # |
 
Проголосовать: нравится +3 Проголосовать: не нравится

I actually solved it slightly differently by deducing the boundaries in $$$O(N)$$$ time.

First, the core observation for the formula: if an element at index $$$i$$$ is the minimum in the exclusive range $$$(l, r)$$$, it is the minimum for exactly $$$(i - l)$$$ valid left endpoints and $$$(r - i)$$$ valid right endpoints. Thus, $$$p[i] = (i - l) \times (r - i)$$$.Instead of searching for a valid root inside a known boundary, we can logically deduce the exact $$$(l, r)$$$ bounds for every element from left to right:Assume the array is padded with $$$-\infty$$$ at both ends. For index $$$0$$$, its previous smaller element is trivially $$$l = -1$$$.Since we know $$$p[0]$$$ and $$$l = -1$$$, we can directly calculate its next smaller element (NSE): $$$r = 0 + \frac{p[0]}{0 - (-1)}$$$.

This index $$$r$$$ gives us two things:Index $$$0$$$ is the absolute minimum of the subarray $$$[1, r-1]$$$ as its Next Smaller element was at $$$p[0]$$$ all the elements in b/w those elements were bigger than $$$0th$$$ element. We can recursively find the bounds for the inner elements $$$[1, r-1]$$$ as the bounds of this subarray is 0 and r which are obviously bigger then all the elements in the subarray giving us effectively $$$-\infty$$$ outer bounds. Now the element at $$$r$$$ is smaller than the element at $$$0$$$, the left boundary of r'th index is also $$$-1$$$ .We repeat the process for $$$r$$$. We use this to find its NSE, $$$r_1$$$, and recursively process the inner subarray $$$[r+1, r_1-1]$$$.By chaining this forward, we calculate the exact $$$[l, r]$$$ bounding box for every single element in $$$O(N)$$$ time.Now we mapped out the exact $$$(l, r)$$$ for every element, we can just build a reverse map: $$$ \lt l, r \gt $$$ -> index.To solve the subsegment $$$(L, R)$$$ finding the smallest index, we just query our reverse map.The key should be present exactly once in the subarray.If it does, let $$$i$$$ be the mapped index. We split the problem into $$$[L, i-1]$$$ and $$$[i+1, R]$$$, and multiply their results by $$$\binom{R - L - 2}{i - L - 1}$$$.

  • »
    »
    3 месяца назад, скрыть # ^ |
    Rev. 4  
    Проголосовать: нравится 0 Проголосовать: не нравится

    I also had a simillar solution to E (378239703), with the difference that ater calcualting (l,r), I created a tree of non-equalities — u is a parent of v if $$$u \lt v$$$ and there is no node x such that $$$u \lt x \lt v$$$. After that I do a dp on the tree where dp[u]=# of possible ways to arrange the subtree of u, where $$$dp[leaf]=1$$$ and dp[u] = MERGE all children of u where $$$MERGE(u,v)=dp[u]*dp[v]*(^{SIZ(u)+SIZ(v)}_{SIZ(u)})$$$. Computing $$$(^n_k)$$$ is done in O(log n), so my solution is O(n log n).

    My question is how do you avoid that log n part in your solution?

  • »
    »
    3 месяца назад, скрыть # ^ |
    Rev. 2  
    Проголосовать: нравится 0 Проголосовать: не нравится

    that's actually so good and easier to understand than author solution

»
3 месяца назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

technique of E is great, but i have no idea how to come up with something like that during the contest and not just believe but proof that

  • »
    »
    3 месяца назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится

    its classic dnc. patterns like this become very obvious over practice.

  • »
    »
    3 месяца назад, скрыть # ^ |
    Rev. 2  
    Проголосовать: нравится +1 Проголосовать: не нравится

    I think it comes with some practice with doing runtime analysis for divide and conquer algorithms (like doing recurrence relations algebraically and also recursion trees), and also just a bit of Russianness. Like in contest I was like "oh brute force search would work but it would be n^2 if the value was near the edges because the recursion tree would be too deep" -> "wait what if I just check the edges first" -> prove the complexity.

»
3 месяца назад, скрыть # |
Rev. 3  
Проголосовать: нравится -8 Проголосовать: не нравится

I observed a interesting observation in D let $$$m = (2^k)+1$$$ The frequency value $$$A_1$$$ and $$$A_n$$$ and $$$Xor(A_1,A_n)$$$ will be $$$Ceil(m/3)$$$, $$$Ceil(m/3)$$$, $$$floor(m/3)$$$. so by this observation you can do it in $$$O(n)$$$ time complexity

»
3 месяца назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

in problem E, isn't it sufficient to find range maximum element on each range and check if it is really the count of subarrays?

  • »
    »
    3 месяца назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится

    Not always. Consider $$$n = 1001$$$, a min at the left or right edge would have 1001 arrays to be the min, but a min at the middle would have $$$501 \cdot 501 = 251{,}001$$$ arrays to be the min.

»
3 месяца назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

D is not 1500 are u kidding me :(

»
3 месяца назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

How can someone think of the optimisation done in E it stills feels like n^2 to me

»
3 месяца назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

For D, can anyone explain how the solution is O(n)? or any resources where I can understand the concept.

»
3 месяца назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Try to come up with a recursive solution that works in (n2) How n2 will pass here?

»
3 месяца назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

The python solution for problem C meets TLE. The same algorithm implemented in C/C++ is accepted.

»
2 месяца назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

In the problem C, the statement was very confusing. And very hard to visualize..