Company: Microsoft_6thaug
Difficulty: medium
There is a row of two-position switches numbered consecutively starting from 1 , all initially in the Off position. The row is long enough to contain every index mentioned below. A series of q operations is performed. Each operation specifies a left index l and a right index r . For that operation, every switch in the inclusive range [l, r] undergoes a NOT operation: a switch that is Off becomes On, and a switch that is On becomes Off. After all operations have been performed, determine the final state of the row and report the sum of all indices whose switch is On. Indices are 1-based. Input Format The first line contains a single integer q , the number of operations. Each of the next q lines contains two space-separated integers l and r , the inclusive range of indices for that operation. Output Format Print a single integer: the sum of the 1-based indices of all switches that are On after all q operations. Constraints 1 <= q <= 8000 1 <= l <= r <= 10^9 The answer can