#P4727. Infinite Inversions
Infinite Inversions
Infinite Inversions
题面翻译
现在有一个由所有正整数组成的无限递增序列: 。
对这个序列执行 次交换操作。每次一个操作,给出两个整数 ,交换位置 和 处的元素。
你的任务是在所有操作结束后,输出最终序列的逆序对个数,即满足 且 的有序数对 的数量。
题目描述
There is an infinite sequence consisting of all positive integers in the increasing order: . We performed swap operations with this sequence. A is an operation of swapping the elements of the sequence on positions and . Your task is to find the number of inversions in the resulting sequence, i.e. the number of such index pairs , that i<j and p_{i}>p_{j} .
输入格式
The first line contains a single integer ( ) — the number of swap operations applied to the sequence.
Each of the next lines contains two integers and ( , ) — the arguments of the swap operation.
输出格式
Print a single integer — the number of inversions in the resulting sequence.
样例 #1
样例输入 #1
2
4 2
1 4
样例输出 #1
4
样例 #2
样例输入 #2
3
1 6
3 4
2 5
样例输出 #2
15
提示
In the first sample the sequence is being modified as follows: . It has 4 inversions formed by index pairs , , and .