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 | 3757 |

2 | jiangly | 3590 |

3 | ksun48 | 3582 |

4 | Um_nik | 3539 |

5 | maroonrk | 3533 |

6 | slime | 3498 |

7 | djq_cpp | 3486 |

8 | Radewoosh | 3442 |

9 | cnnfls_csy | 3427 |

10 | ko_osaga | 3355 |

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

1 | -is-this-fft- | 185 |

2 | awoo | 181 |

3 | dario2994 | 171 |

4 | SecondThread | 169 |

4 | maroonrk | 169 |

6 | Um_nik | 168 |

7 | adamant | 166 |

8 | YouKn0wWho | 165 |

8 | errorgorn | 165 |

10 | antontrygubO_o | 162 |

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

The only programming contests Web 2.0 platform

Server time: Oct/04/2022 12:35:02 (j3).

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