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

Автор Bakry, история, 5 лет назад, По-английски
Tutorial is loading...
Tutorial is loading...
Tutorial is loading...
Tutorial is loading...
Tutorial is loading...
Tutorial is loading...
Tutorial is loading...
Разбор задач Codeforces Round 746 (Div. 2)
  • Проголосовать: нравится
  • +267
  • Проголосовать: не нравится

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

Wow, that was quick.

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

The contest was awesome, Even system testing was fast :D

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

In problem D, you can do binary search directly on the bfs order (search for the shortest prefix having value same as the value of whole array) which will save 1 query I think.

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

Thanks for the quick editorial

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

It was a miracle. compared to current speed of posting of editorials.

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

B is Great!!!

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

Loved problem E.

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

What was the intuition to B? like I got to know that what will work but what is the line of thinking (approach) to solve this problem ?

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

You could just sort the edges and do binary search on D

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

nice contest. fast systest and editorial :D

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

Thanks for the fast editorial. For problem C, may I ask that how do we find the two required edges to break the tree into 3 parts with xor sum of each component equal to x in O(n) or O(n lg n) time? I have been trying to solve this problem but I am stuck at the implementation.

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

I Think, in problem A, ans should be "H / (x + y)" multiple by 2

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

Thank you for a great round and fast editorial!

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

Thanks for the contest, good pretests and quick testing!:)

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

Thanks for fast editorial!

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

Are there any provements for C that the deepest subtree erase is always right?

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

    If we do not choose the deepest subtree we might mistake choosing a subtree which has three (2n+1) subtrees in itself who individual XORes is equal to the XOR of all the nodes in the given tree. And unfortunately we might not find any other subtree with the required XOR.

»
5 лет назад, скрыть # |
← Rev. 2  
Проголосовать: нравится +8 Проголосовать: не нравится

Problem D could've been solved relatively naively due to the limit being $$$n \lt 10^3$$$, ie. without any consideration in which order to process edges. Simply maintain the set $$$E$$$ of suspected edges and traverse graph in any way you like (in my case it was DFS) until you enumerate $$$|E| / 2$$$ suspected edges (for the binary search part; edge set will be denoted as $$$E'$$$). Collect all the visited nodes into a single query, and if this query gives the same result as the initial query for the whole graph, set $$$E = E'$$$. Otherwise, $$$E = E \setminus E'$$$.

Of course, each time we print a large portion of the tree just because we enumerate zounds of "unsuspected" edges. What I mean to say is that there was no need for consideration of Euler tours nor to care about efficient implementation.

Btw, this makes IO load equal to $$$O (n log n)$$$ rather than amortized $$$O(n)$$$ as in editorial.

Also, I liked this problem a lot :)

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

    Could you please explain why is it O(N log N)?

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

      Most cases you will enumerate lots of edges that are not in set $$$E$$$, because we queried about them already. In other words, almost every query will be about a set of O(n) vertices. There are O(log n) queries, thus O(n log n) vertices printed in all the queries.

      For example, imagine a path of length 512. First you enumerate ~256 vertices. If the sought-after edge is not there, in the next query, if you start dfs from the same source, you need to query 256 + 128 = 384 vertices rather than just 128 (because first 256 vertices enumerate only edges not in $$$E$$$, and you need to print a whole connected component). Etc.

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

        Though I checked my submission 130706195 and it seems that during the round I mitigated this problem, because I stored the visited component as a set of suspected edges from this component (the $$$qry$$$ variable). And instead of querying vertices from the whole component, I print only those adjacent to at least one $$$qry$$$ edge. It seems that this trick makes all queries to contain at most $$$n + 2n - 2$$$ vertices in total = $$$O(n)$$$.

        Anyway, $$$O(n log n)$$$ should pass as well (ie. if you stored vertices from the component rather than edges).

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

    Sorry for the necropost, but I had a very similar idea in mind, and it looks like it is nlogn as well ( maybe nlog^2n ), but it TLEs. Not sure how to optimize it or if its even worth trying. Here is the link: 214129320 Could you let me know what I am missing or if I should just try and go for the intended sol?

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

      Sorry for the late response: It seems that your search for a set of half of the edges is quadratic (due to running a BFS for each vertex). I did not analyse very deeply but this is what seems to be the case. And this complexity times twelve queries takes you above 1000ms time limit. At least it seems like so.

      Hint: It is much easier to switch your viewpoint from tracking vertices (ie. sub forests) to edges (this may very well be a set of disconnected edges). Just pick a set of edges to query for and the actual query is all vertices that are endpoints of the selected edges. Then you require only a single DFS / BFS per query (so that the endpoints do not mark unwanted edge that should belong to the set "right"; example if you are left with a path 1 — 2 — 3 — 4 and you want to select 2 edges, do not accidentally pick 1-2 and 3-4, because the set of all endpoints is {1,2,3,4} and it's incorrect. You should pick edges 1-2 and 2-3 or 2-3 and 3-4. The set of edges can be selected with a single DFS).

      [Edit] Hint 2: In this problem you can very easily prepare testcase with n = 1000, by just making a path or a star graph. Then you can play with where the bottleneck is.

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

In problem A ans=(h/x+y)*2

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

Could anyone please explain me that why does this submission 130717510 to D fail because I guess that this approach was fully correct. Moreover can anyone explain me why does this submission pass 130725042. I cannot find any valid reason for this and am doubting this to be a case of bad test cases

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

Can anybody disprove the following?

We can split into 3 components if we can find a subtree (not the tree itself) that has $$$xor$$$ equal to the $$$xor$$$ of the whole tree.

I am getting wrong on the test 10, with this idea. Solution.

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

Now this is a great round. A-C were creative and easy to code, D required some implementation, E was just beautiful and no "fancy" algorithms appeared until F2, the hardest problem.

A perfect example of how div2 rounds should be prepared.

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

rel-a-table

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

Systest for C seems to be weak. I wrote something nonsensical (count all edges that can split the graph into zero and the target xor value). But it can be uphacked with this simple test case:

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

For problem D maybe my solution can be hacked because my basic idea was finding maximum edge at first by 1 query. After that split the tree to 2 trees so that new smaller trees have 1 common node and their union is current tree. Also while choosing this 2 trees we are minimizing their size difference. Now after splitting we can easily ask one query about them and determine which one includes max edge and continue to process until our tree has only 2 nodes. This works quite well but I can't create worst case scenario If you know how to do it please share your ideas. my code

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

    My friend hacked my solution post-contest with randomly generated trees.

    My solution selects half of the remaining nodes by starting from a random node and dfs, and repeat if necessary.

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

    Hacked with a tree, where each node has $$$9$$$ children. $$$n=820$$$, it has $$$3$$$ layers, and in the worst case it is $$$4$$$ question to handle each of them. $$$3*4+1 \gt 12$$$. I think a similar construction works, where each node has $$$5$$$ children.

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

How can E be solved in $$$O(NlogN)$$$? According to editorial, it looks like the time complexity should be $$$O(N^2 logN)$$$

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

    I only know a solution in Nlog(max A), I think the editorial meant that it's solved by iterating k giving total complexity N(logN ?)logmaxA. One observation you can do is that you can split the array into intervals [x, y], where for all positions k is set, and then find tho positions which are furthest apart with the same xor (in the interval [x-1, y]), but with the same parity of indices.

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

In problem E, shouldn't be $$$r-l+1$$$ is even, instead of odd?

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

As always, here are the video solutions to the first three problems : solutions

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

It's not solution but I want to share idea about 1592D - Hemose in ICPC ?. You should know that tree is bipartite graph. Let's say one partition is array a, and other partition is array b. Request answer for 1,2,...,n. Let's say it's r. Now, repeat following:

  • if partition a bigger than b, just swap them.
  • now split array b (array of vertices) into two halves c and d, or closest size. Because in bipartite graph each edge goes from one partition to other, we get that edges connecting a and c are different to edges connecting a and d, and together they make whole set of edges between a and b.
  • ask about vertices a + c.
  • if result is less than r, then say new partitions are a and d, otherwise new partitions are a and c.

Do this until we get 1 vertex in both partitions. I didn't proof how many requests it does in worst case, but I guess it's around 17 (case 500 size of both partitions). So it's a little bit more than we can afford. Sad. But very easy to implement. 130691922

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

    For some reason, if I remove isolated vertices each time before the check for swap, then it get wrong answer, but it should be request limit exceed if idea above is correct. Something is wrong. 130827040

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

      I found bug. Proof above is wrong.

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

The contest was fun, but i think the editorial is kinda bad. For example, on E, what is "which can be solved easily in O(NlogN)" supposed to mean? If you're not gonna explain the solution at least put code so people can learn what to do.

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

me: thinks I can pass 1000 this round

codeforces: nope, here's your 999

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

Can someone break my idea for D? Im finding the centroid of the tree and doing a knapsack to find the value closest to n/2 you can get by summing subtrees of the children of the centroid and do a query with those subtrees + the centroid. If the value you get by doing it is less than the answer, you remove all those children from the tree (i.e mark them) and repeat that algorithm until i have 2 nodes.

Code: 130722106

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

why we multiple by 2 in problem a?

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

    Because we're using two weapons. Think of the case where h = 10 and the two weapons are 5 and 4

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

      bro i don't understand all equations for problem a Can you explain them?

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

        Assuming you understood the first part of the editorial:

        The ammount of times we can be 100% confident we can use both weapons will be h/(x+y) (the ammount of times we can fit both of them in h).

        That would cost (h/(x+y))*2 operations and leave h-(h/(x+y))*(x+y) hp remaining (each time we take x+y hp off, and we will do it h/(x+y) times). We can notice that this is the remainder on the division of h by (x+y), or h mod(x+y) or in c++ h%(x+y).

        Since the hp remaning after that will be smaller than x+y, you will either use x or x and y if it is bigger than x.

        If you still cant get it, do some cases by hand and/or read the editorial and this comment again

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

Hemose Bakry there is unproved part for C. "If you can partition the tree into m components".. how do I prove this?

Can you please help in proving if these (below) are the components with every one of them with xor=x, we can have another set of 3 legal components?

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

In problem C, Can anyone explain how do we search for the 2 edges in the tree?

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

F1 and F2 are one of the best F problems I have seen before: It's really difficult to come up with the correct ideas, but the solutions are quite short.

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

In the editorial of F2, perhaps "if" is spelled wrong in the last paragraph:(

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

Can someone give me a solution to D problem in simpler words, I just can't understand it from the editorial.

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

Nice Contest and finally I have become a PUPIL.

I was able to solve both A and B within 45 mins for the first time and got stuck at C without knowing trees .

Can anyone explain E please?

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

In D can't we just take half the edges every time?

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

    We can't do this in simple way. Because edges are defined by vertices we ask. So if we want to check edges (1,2) and (3,4) just two edges, then answer to our question will also may have edge (2,3) if (2,3) is connected in initial graph.

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

      r57shell, can you explain why the binary search on the Euler Tour will never "leave edges behind"? Like, edges whose one endpoint is to the left of the midpoint and the other endpoint is to the right. I understand that that won't happen on the first or second split, but it's not clear why that won't happen as the binary search progresses.

      • »
        »
        »
        »
        5 лет назад, скрыть # ^ |
         
        Проголосовать: нравится +3 Проголосовать: не нравится
        Explanation turned out to be long
        • »
          »
          »
          »
          »
          5 лет назад, скрыть # ^ |
           
          Проголосовать: нравится 0 Проголосовать: не нравится

          But when you go through (u, v) the first time, you add "u v" to the Euler Tour. The second time you go through (u, v), you add "v u". Assuming the answer is (u, v), isn't it possible that one of the binary search splits will put "u v" in separate segments ("u | v"), pick the segment that contains "v u" (since that is the answer) and later on another binary search split will put "v u" in separate segments ("v | u") and now the answer won't be in either segment?

          Maybe you tried to answer that, but I still can't see why that wouldn't happen...

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

            Ah, you should not do that. You should cut segment by half of its edges, it's not the same as to cut array of vertices into two halves. You either take edge u->v or not take. If in first choice is M edges, then in other is N-M edges where N is total edges (not vertices).

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

    Lets say we did simpe dfs and got edges as {1,2} {2,3} {1,4} {4,5} {1,6} {6,7}

    Now lets query for first three edges

    query({1,2}{2,3}{1,4}) === query(1,2,3,4) To ask a query about a set of k nodes v1,v2,…,vk (2≤k≤n2≤k≤n, 1≤vi≤n1≤vi≤n, all vi are distinct)

    we get the max gcd and max gcd edge was actually there in our query edge set. But what if we query last three edges

    Query ({4,5} {1,6} {6,7}) === query (4,5,1,7)

    Note that result of this query we will get, would still be max gcd, coz 1 and 4 is present in the query and so the edge {1,4} . However, our edge set for this query didn’t have this edge.

    So, we need to use edge set formed using Euler tour.

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

For F2, I don't think we need to search for all the values of k in: 0<=k<=K, because using the second operation once saves us one coin (with type one operation we will use 3 coins and with type 2 we will use 2 coins). The only corner case is by using the second operation we might change a[n][m] from 0 to 1, but even in that case, it can be rectified with just one additional coin which was our profit from the last type 2 operation we made.

Thus using the maximum number of type 2 operations always works :)

Thanks for an amazing contest and a really amazing set of problems. Liked the E problem especially.

I hope you would do this change in F2's tutorial so that it becomes slightly easier for the viewers to understand and code :)

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

finally a specialist =)

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

in problem E how do you check the condition that pref[r] ^ pref[l-1]==0 fast?

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

The Observations in the Div2 C question is same as this question — https://codeforces.me/problemset/problem/1516/B

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

My explanation for Problem E. Commented source code, see 130804026.

Let's look at $$$2, 3, 5, 3, 7, 5, 1, 4$$$. I will write the numbers in binary in columns:

What the task now translates to is: Find the longest row of continuous $$$1$$$s with the following property: The length of the sequence is even and each horizontal segment above your sequence contains an even number of $$$1$$$s. Examples are:

Only the first and the last example are valid. The last one is the longest valid example. How do we find this longest sequence? We will need to iterate over each bit (row) and each value (column). Let's assume we iterate over row $$$k$$$

. What we now want is a prefix-xor-sum for all values above our row $$$k$$$ (those are called important in the editorial).

We also color the values in the xor-sum alternating in 2 colors. We will need this to achieve the even length of the sequence. Now we iterate row $$$k$$$ with $$$r$$$ from left to right and for each $$$r$$$ we keep the value $$$l$$$ which denotes the last position with a $$$0$$$ (We handle position 0 as also having value $$$0$$$, so $$$l$$$ starts with 0):

We now want to to find the smallest $$$l_{ans}$$$ such that $$$l \leq l_{ans} \leq r$$$ and that the xor-sum of all values in $$$(l_{ans},r]$$$ is equal to $$$0$$$. This is equivalent to finding $$$l_{ans}$$$ such that the xor-sums of $$$(0, l_{ans}]$$$ and $$$(0, r]$$$ are equal. To achieve the parity in the length of the segment we also need, that $$$r$$$ and $$$l_{ans}$$$ have the same color:

How do we find this $$$l_{ans}$$$? We could create a map that saves for each possible xor-sum value and both colors all the positions this xor-sum appears at and then do a binary search. This would get as a $$$\log(N)$$$ for the binary search and a $$$\log(a_i)$$$ for the map and this will TLE 130742189. We can replace the map with just a vector with $$$2^{20}$$$ values. This will get accepted, but just barely 130742292! Another improvement is, we do not need the binary search. While iterating $$$r$$$ we can keep for each possible xor-sum the earliest appearance in our $$$1$$$ s-segment. This way we get rid of the second $$$\log(N)$$$-factor and this solution gets accepted easily 130804026. The final complexity is $$$O(N \log a_i)$$$, for iterating both $$$k$$$ and $$$r$$$.

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

Why in C we do we need to go to the deepest subtree? Why can't we take any subtree whose xor is x?

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

    XOR value of subtree 3 is 4.
    But if you delete the edge (2,3) first, it is impossible to partition the tree into three components with equal XOR values.

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

C is really nice, the m-2 idea is sneaky

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

I'm trying to solve problem D in the following way:

After getting max value by querying N nodes, query for N/2 nodes.

If the ans is less than max, then remove all the edges which are made up these nodes at both the ends.

If the ans is max, then keep all the edges which are made up these nodes at both the ends, remove other edges.

With the help of remaining edges, again figure out N/4 nodes, and query it. Keep going this way, and in the end, only one edge will remain.

Any issue with this approach?

The solution is failing : https://codeforces.me/contest/1592/submission/130812435 . Is there a logical bug or an implementation bug?

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

    In this way, you cannot guarantee every time you make a query, you really half the size of the set of possible edges that could becomes the answer. I believe that some of the pretests block this approach but I'm not sure .

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

In the F1 problem , the editorial makes a new grid using parity of sum of (i,j) , (i+1,j) , (i,j+1) and (i+1,j+1) and solves for this one...is this a common technique?

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

    To get a feeling, you can look at it the other way first. If you want to flip $$$(x,y)$$$ using rectangles containing $$$(1,1)$$$ without flipping other cells, how do you achieve this? You achieve this, by doing operations on $$$(x-1,y-1)$$$, $$$(x-1,y)$$$, $$$(x,y-1)$$$ and $$$(x,y)$$$. If you got several bits you want to flip, then you can add those operations. You notice, doing this operation twice on a cell will keep everything the same. So we can handle the operations as "activate" and "deactivate" the operation on some $$$(a,b)$$$. The editorial now turns this around, by transforming each 4-operations flip into a single cell. This is easily possible, because we found a sequence of operations, that flip exactly one cell.

    I guess you can find similarities to [Lights Out](https://en.wikipedia.org/wiki/Lights_Out_(game)) (I'm really sorry, I somehow can't link this. Guess because there are brackets in the link maybe...?) although the transformation is not so easy, because there is no simple sequence to swap exactly one cell in this case.

    You could also try and learn more about linear algebra to get a better feeling for this.

    So yes, I'd say it is a useful technique to group some operations with special properties and then transform the problem into that group-view.

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

Someone please help me find the mistake in my code for problem 2c....it is giving TLE on 3rd test case (https://codeforces.me/contest/1592/submission/131055533)

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

His all submissions in this contest are shrinked deliberately. I know it is rule violation. 130676197

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

Can anybody please share the implementation for problem c and possibly explain how exactly are we going to do what has been mentioned as the last step in the editorial?