First, how can we say that an array is a permutation?

Suppose array length is nn, then sum of the permutation should be n(n+1)/2n*(n+1)/2, minimum value of permutation is 11, maximum value of permutation is nn. Is that enough? No, we can also check the XORXOR sum of the permutation. So, if an array holds these 4 conditions we can say that this array holds a permutation.

Now, how can we solve for the range of an array? We can maintain range xor, range sum, range minimum, range maximum using data structure. Now How can we solve the update part? Update only for an index at a time. So we can update in O(log(n)) time and overall complexity is O(n+qlog(n)).

Statistics

65% Solution Ratio
NirjhorEarliest, Nov '21
Azizul_cse27Fastest, 0.0s
Azizul_cse27Lightest, 27 kB
serotoninShortest, 1201B
Toph uses cookies. By continuing you agree to our Cookie Policy.