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.

Rating changes for the last round are temporarily rolled back. They will be returned soon.
×

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

1 | antontrygubO_o | 192 |

2 | Errichto | 185 |

3 | tourist | 182 |

4 | vovuh | 171 |

5 | pikmike | 169 |

6 | Radewoosh | 164 |

7 | ko_osaga | 162 |

8 | Um_nik | 161 |

9 | 300iq | 156 |

10 | Petr | 154 |

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-2020 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: Mar/28/2020 17:45:37 (g1).

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