当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

4988:Little Pony and Boast Busters

题目描述
"I hereby challenge you, Ponyvillians: anything you can do, I can do better. Any takers? Anyone? Or is Trixie destined to be the greatest equine who has ever lived!?!" — "Boast Busters"

Given two permutation P0 && P1 of {0, 1, ..., n - 1}, we define the crossing number of it as follows. Write P0 from left to right above P1 and draw a straight line between each same elements. The crossing number of P0 and P1 is the number of pairs of lines that cross.

For example, if n = 5, and P0 = {0, 1, 2, 3, 4}, and P1 = {1, 3, 0, 2, 4}, then the crossing number of P0 and P1 is 3, as shown in the figure below.


Now given you the two permutation, you need to implement the following operations:

SWAP p a b: swap Pp[a] and Pp[b] (0<=p<=1, 0<=a, b<=n-1).

QUERY: ask the crossing number of the current P0 and P1.
输入解释
Input contains multiple test cases (less than 10). For each test case, the first line contains one integer n (1<=n<=10^5).
The second line contains n integers P0[0], P0[1], ..., P0[n-1].
The third line contains n integers P1[0], P1[1], ..., P1[n-1].
The next line contains one integer q —— the number of operations (1<=q<=10^5). The next q line, each line will contains a operation as we mentioned above.
输出解释
For each query, output the corresponding result in one line.
输入样例
5
0 1 2 3 4
1 3 0 2 4
5
QUERY
SWAP 1 2 4
QUERY
SWAP 0 2 4
QUERY
输出样例
3
6
5
来自杭电HDUOJ的附加信息
Recommend heyang

该题目是Virtual Judge题目,来自 杭电HDUOJ

题目来源 BestCoder Round #7

源链接: HDU-4988

最后修改于 2020-10-25T23:18:44+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
20000/10000MS(Java/Others) 131072/131072K(Java/Others)