← ALL NOTES
Array

3841. Palindromic Path Queries in a Tree

A multiset of letters rearranges into a palindrome exactly when at most one letter has odd count, so the only thing a path needs to report is 26 parity bits — and parity composes under XOR. Hang the XOR of letter-bits from the root on every node as mask[u], and the path u..v collapses to mask[u] ^ mask[v] ^ bit(s[lca]): everything strictly above the LCA appears in both prefixes and cancels, and the LCA's own letter cancels one time too many, so it goes back in by hand.

Loading…