Блог пользователя bully....maguire

Автор bully....maguire, 6 лет назад, По-английски

I usually make observations whenever i am not able to solve some problem.

In round 682 , I found that problem C,D,E were not solved by many people but after hints and editorials was given lot of people upsolved them.

Let us take problem E :

I was not able to solve this problem on my own . But if we see the editorial , it's just based on simple observation that sum of elements should have bit higher than border elements . Prove for efficiency is also very easy.

I did not asked these questions to myself while solving the problem.

Usually i see that i have solve lot problems before i am able to solve some problem of similar type.But this way of practicing will take lot of time to become good coder.

You see that understanding the solution is a cakewalk , but coming up by yourself is difficult . Is this due to laziness i.e out brain not used to it ?

So i ask people for their opinions on it.

I would also like to hear the suggestions of people of all colors (from unrated,newbie to LGM).

I have watched stream of these red coders and i see that they solve problems without much thinking but i am sure this was not the case when they were 2 to 3 year experienced in the field.

I genuinely want you people opinions. After getting around -15 votes it will automatically become invisible from recent actions.

  • Проголосовать: нравится
  • -26
  • Проголосовать: не нравится

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

Don't tag me for help with random problem. I answer CF blogs when I have time.

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

I also had similar type of issue in this contest, I was unable to come up with correct approach for D during contest, but after words reading editorial I realized I was approaching this problem in totally wrong way. I think, someone who solve this type of problems easily should suggest some ways/techniques for practice/thinking for relative topics. It would be really helpful for people like me :)

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

For problem C, it helps to think of the grid graph: squares are vertices, edges are drawn between neighboring squares. You may have previously encountered its property we need: the graph is bipartite, so it can be colored using only two colors such that neighbors have different colors. Visualizing the whole board as a chessboard, with its black and white squares, also helps.


For problem D, it helps to look at some general characteristics of the array, trying to find invariant properties. Specifically, what remains constant after the allowed operation? One such property is the xor-sum of the whole array. Now remember that a xor a = 0, a xor a xor a = a, and such. What you get is that, for an odd array, in the end, its xor-sum should be equal to every element, and for an even array, its xor-sum should be zero. Now we see, in particular, that any even-length array with xor-sum not equal to zero gives the answer NO.

Let's focus on odd arrays then. Next, we will try to get any one value which would be equal to $$$a_1 \oplus a_2 \oplus \ldots \oplus a_n$$$. To do that, we can xor $$$(a_1, a_2, a_3)$$$, then xor $$$(a_3^{\mathrm{new}}, a_4, a_5)$$$, then $$$(a_5^{\mathrm{new}}, a_6, a_7)$$$, and so on. In an odd array, what we get for $$$n = 7$$$, for example, is

a_1  ->  a_1 ^ a_2 ^ a_3
a_2  ->  a_1 ^ a_2 ^ a_3
a_3  ->  a_1 ^ a_2 ^ a_3 ^ a_4 ^ a_5
a_4  ->  a_1 ^ a_2 ^ a_3 ^ a_4 ^ a_5
a_5  ->  a_1 ^ a_2 ^ a_3 ^ a_4 ^ a_5 ^ a_6 ^ a_7
a_6  ->  a_1 ^ a_2 ^ a_3 ^ a_4 ^ a_5 ^ a_6 ^ a_7
a_7  ->  a_1 ^ a_2 ^ a_3 ^ a_4 ^ a_5 ^ a_6 ^ a_7

Now we can spread the last element back: for example, xor-ing the current values of $$$(a_3, a_4, a_5)$$$ makes them all equal to the xor-sum of all array. Then xor the current values of $$$(a_1, a_2, a_3)$$$ to get them all equal.

The final observation is how it helps with an even-length array. Let us do what we already learned to do, for the odd part, and the last element will remain untouched. So for $$$n = 8$$$, for example, the array looks like this:

a_1  ->  a_1 ^ a_2 ^ a_3 ^ a_4 ^ a_5 ^ a_6 ^ a_7
a_2  ->  a_1 ^ a_2 ^ a_3 ^ a_4 ^ a_5 ^ a_6 ^ a_7
a_3  ->  a_1 ^ a_2 ^ a_3 ^ a_4 ^ a_5 ^ a_6 ^ a_7
a_4  ->  a_1 ^ a_2 ^ a_3 ^ a_4 ^ a_5 ^ a_6 ^ a_7
a_5  ->  a_1 ^ a_2 ^ a_3 ^ a_4 ^ a_5 ^ a_6 ^ a_7
a_6  ->  a_1 ^ a_2 ^ a_3 ^ a_4 ^ a_5 ^ a_6 ^ a_7
a_7  ->  a_1 ^ a_2 ^ a_3 ^ a_4 ^ a_5 ^ a_6 ^ a_7
a_8  ->  a_8

But as the xor-sum is zero (otherwise, we already know to answer NO), we see that a_1 ^ a_2 ^ a_3 ^ a_4 ^ a_5 ^ a_6 ^ a_7 must now be equal to a_8. The actual program might go the other way, comparing them and writing YES or NO as the result.


For problem E, the key idea for me was something like this. Let us fix one end of the subarray, and move the other one away. Suppose we have the inner sum $$$S$$$ equal to the xor-sum of the border values. Then we include one of the border values in the sum. If the included border was large, then the sum increased significantly (to somewhere around $$$2S$$$). So there are only few such events (on the order of $$$\log_2 (10^9)$$$).

I didn't manage to do the next nice observation and the neat symmetric solution, but got something along the above lines, presumably working in $$$O (n \log^2 n)$$$, with another $$$\log n$$$ factor resulting from binary search.