# | User | Rating |
---|---|---|

1 | tourist | 3434 |

2 | fateice | 3337 |

3 | Um_nik | 3292 |

4 | OO0OOO00O0OOO0O0…O | 3280 |

5 | Syloviaely | 3274 |

6 | Petr | 3223 |

7 | Swistakk | 3105 |

8 | mnbvmar | 3096 |

9 | yosupo | 3091 |

10 | dotorya | 3081 |

# | User | Contrib. |
---|---|---|

1 | rng_58 | 164 |

2 | tourist | 161 |

3 | csacademy | 153 |

4 | Petr | 150 |

5 | Swistakk | 148 |

6 | Um_nik | 144 |

7 | Nickolas | 142 |

7 | Vovuh | 142 |

9 | BledDest | 138 |

9 | PikMike | 138 |

9 | matthew99 | 138 |

9 | Errichto | 138 |

Codeforces (c) Copyright 2010-2018 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: Jul/20/2018 15:54:36 (d1).

Desktop version, switch to mobile version.

User lists

Name |
---|

I think I've seen the matrix restoration and array restoration problem somewhere before.

How to solve Chef Restores an Array?

Here is the problem link

Two adjacent numbers are either related by a +/-1 or not related at all. If they are related by both, ans is 0. To find the relations in linear time, we can use 2 prefix DPs, one for 'I' relations and the other for 'D' relations.

From numbers you already know, you can traverse using known relations(edges) to get unknown numbers and at same time verify other known numbers. We need to make sure that these numbers are in the range [1,

k]. For numbers that are still unknown, they will form a forest of chains. In each of these chains, we need to see the difference between the largest and smallest.Editorials please

chemthan(or anybody else) can you explain the approach for the maximum path on tree question???

Firstly we ignore

gcd(u,v), just find the maximum ofdist(u,v)·min(u,v). Iterating vertices in decreasing order by values written on them and maintain DSU structure. Each time we connect an edge (u,v), we're only interested in paths pass through that edge. We will maintain diameter of each component. If (x,y) is diameter ofu's component, (z,t) is diameter ofv's component then the longest path passes through (u,v) is among (x,z), (x,t), (y,z), (y,t). Complexity isO(LCA(N) +DSU(N)).Now, finding the maximum of

dist(u,v)·min(u,v)·gcd(u,v): For eachd, we consider only vertices that values written on them are multiplier ofdand apply above approche for each group. The sum of all groups is at mostN*max_number_of_divisor_of(a[i]) ~ 6e6. We can optimize LCA part by using LCA O(1) per query, so total complexity will beO(DSU(N*max_number_of_divisor_of(a[i])).how do you solve |S|*AND(S) problem

fix the AND, iterate over supermasks, find largest connected component with dsu.

there are ~2^20 possible values for the AND right? How would you use DSU to find the largest connected component for each value of AND?

say we want to make the and equal to x, add the vertices that are supermasks of x one by one. After adding one we check if its parent is also supermask of x, if that is the case we merge them with dsu. Complexity: 3^17