Comments

maybe we can get a solution for C by using segmenttree.

then we can

we can solve this by dp twice and using seg to tag