this hard version problem the difference easy hard version constraint a_i n you hack version problem solvedburenka crown princess Buryatia soon nth queen country there ancient tradition Buryatia coronation ruler strength inhabitant to determine strength nth ruler inhabitant country array exactly n number ruler turn element array zero short time the ruler follow twostep operation number time select index l r 1 le l le r le n nonnegative integer x l leq leq r assign a_i a_i oplus x oplus denote bitwise XOR operation it take leftlceil fracrl12 rightrceil seconds operation lceil y rceil denote y round near integer help Burenka calculate time need