ExpediaOA #4
Calculate the Sum
困难可在线判题
考点(AI 标注)前缀和区间
Switches are numbered consecutively starting from 1, and all of them are initially off. For each closed interval [l,r] in order, toggle every switch in it: off becomes on and on becomes off. Find the sum of the indices of the switches that are on at the end, not the number of them; repeated operations can cancel each other out.
输入格式
The input contains the number of operations n, followed by n pairs of left and right endpoints, separated by whitespace; LF/CRLF and a direct EOF are supported. The original constraints section has no numbers; based on the original Java int/int[][] types, this site openly adapts the range to 1≤l≤r≤2147483647. n≥0 and is limited only by the existing 32MiB standard input budget; no smaller cap on the number of operations is added. n=0 is an explicit mathematical extension meaning no operations.
输出格式
Output the sum of the indices of the switches that end up on, as an exact integer with no modulo. The original int return type is too narrow, so this site explicitly uses a 64-bit result; the maximum is 2305843008139952128.
样例 1
输入:
2
1 3
2 4
输出:
5
样例 2
输入:
2
2 5
2 5
输出:
0
样例 3
输入:
1
2147483647 2147483647
输出:
2147483647
样例说明
The original has no examples; all three public examples are constructed by this site: after [1,3] and [2,4], only 1 and 4 are on, for a sum of 5; toggling [2,5] twice gives 0; toggling [INT_MAX,INT_MAX] once gives 2147483647. The right end of a closed interval must be included, and the endpoint range comes from an explicit type adaptation rather than from numeric constraints in the original.