Unfortunately Codeforces fails to show formulas in an editorial and I can't even press on "Preview" button :( While it doesn't work as intended, I put a bit ugly pdf-version of an editorial here. Unfortunately without model solution sources yet.

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

1 | tourist | 3557 |

2 | wxhtxdy | 3512 |

3 | Um_nik | 3355 |

4 | Radewoosh | 3344 |

5 | Benq | 3316 |

6 | LHiC | 3302 |

7 | Petr | 3293 |

8 | yutaka1999 | 3190 |

9 | ainta | 3180 |

10 | mnbvmar | 3128 |

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

1 | Errichto | 193 |

2 | Radewoosh | 173 |

3 | PikMike | 164 |

4 | Vovuh | 161 |

4 | rng_58 | 161 |

6 | majk | 157 |

6 | 300iq | 157 |

8 | antontrygubO_o | 156 |

9 | Um_nik | 151 |

10 | kostka | 148 |

Unfortunately Codeforces fails to show formulas in an editorial and I can't even press on "Preview" button :( While it doesn't work as intended, I put a bit ugly pdf-version of an editorial here. Unfortunately without model solution sources yet.

↑

↓

Codeforces (c) Copyright 2010-2019 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: Sep/18/2019 00:43:20 (f3).

Desktop version, switch to mobile version.

Supported by

User lists

Name |
---|

" ... Pascal triangle and started to investigate properties of binomial coefficients located on the same line. That was the wrong way :)"

This is also a good way, the "Pascal triangle" tells me that we are finding coefficients of

x^{c}in (x^{a}+x^{b})^{0}+ (x^{a}+x^{b})^{1}+ (x^{a}+x^{b})^{2}+ ..., then it is easy to see S(C) = S(C-A) + S(C-B).Want to share my solution to E. It's seems to be isomorphic to what is written in the editorial but If I was to implement what is in editorial I would get much harder solution.

Let's root the tree in any vertex, now suppose pair of vertices u,v (

a_{u}<a_{v}). Ifvis not in the subtree ofuthen it adds 1 to answer of all vertices in subtree ofu. If it in the subtree ofto— some direct child ofuthen it adds 1 to answer of all vertices except vertices in subtree oftowhich means add 1 everywhere and add -1 to subtree oftoNow process vertices

uin decreasing order of its value in groups of vertices of same value: you need to know how many verticesvin each subtree (it's a range query) and outside of subtree ofu(it's all others), and add answers to some subtrees. Adding to subtrees is either adding to a range in tin order or may be done offline.Code