Q flowers DP atcoder

just saying a segment/fwt tree solution should be possible too
MY AC CODE OF ATCODER