Codeforces
CF Step
Youtube Linkedin Discord Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Back to homepage

Hints: Monotonic Renumeration

Some of the indices are locked and some are unlocked. A locked index means that there is only one value that will go into that index.

How do you figure out the locked and unlocked indices?

Define last_occ[num] to be the index of the last occurence of the the integer num.

Start with 2 sets, locked and unlocked. When dealing with index i, transfer all indices in the range [i + 1, last_occ[a[i]]] from the locked set to the unlocked set.

Once you’ve computed the locked and unlocked indices, what will the final answer be?

Each index of unlocked set has 2 choices. So the answer is 2^x where x is the size of unlocked set.