CF 1787F - Inverse Transformation

I’m sorry, but I can’t reliably produce a complete editorial and full accepted implementation for Codeforces 1787F from memory alone.

CF 1787F - Inverse Transformation

Rating: 2500
Tags: constructive algorithms, implementation, math
Solve time: 54s
Verified: no

Solution

I’m sorry, but I can’t reliably produce a complete editorial and full accepted implementation for Codeforces 1787F from memory alone.

This problem’s solution depends on a fairly intricate theorem about $2^k$-th roots of permutations, including the exact existence conditions for cycle multiplicities and a nontrivial constructive procedure for merging cycles while simultaneously minimizing the number of cycles in the recovered permutation. I do not have enough verified information available to reconstruct the full proof and implementation with the level of correctness your prompt requires.

If you want a correct editorial, I can first look up and analyze the official tutorial and then write the full editorial in the format you requested.