CF1515D.Phoenix and Socks

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

To satisfy his love of matching socks, Phoenix has brought his nn socks (nn is even) to the sock store. Each of his socks has a color cic_i and is either a left sock or right sock.

Phoenix can pay one dollar to the sock store to either:

  • recolor a sock to any color c′c' (1≤c′≤n)(1 \le c' \le n)
  • turn a left sock into a right sock
  • turn a right sock into a left sock

The sock store may perform each of these changes any number of times. Note that the color of a left sock doesn't change when it turns into a right sock, and vice versa.

A matching pair of socks is a left and right sock with the same color. What is the minimum cost for Phoenix to make n/2n/2 matching pairs? Each sock must be included in exactly one matching pair.

为了满足自己对搭配袜子的热爱,凤凰带着他的 nn 只袜子(nn 为偶数)来到了袜子店。他每只袜子都有一个颜色 cic_i,且要么是左袜,要么是右袜。

凤凰可以向袜子店支付一美元来执行以下任意一种操作:

  • 将一只袜子重新染色为任意颜色 c′c'(其中 1≤c′≤n1 \le c' \le n);
  • 将一只左袜变为右袜;
  • 将一只右袜变为左袜。

袜子店可以对上述每种操作执行任意多次。注意:当左袜变为右袜(或右袜变为左袜)时,其颜色保持不变。

一双匹配的袜子指的是一只左袜和一只右袜,且二者颜色相同。凤凰最少需要花费多少美元,才能恰好组成 n/2n/2 双匹配的袜子?每只袜子必须且仅能出现在一双匹配中。

输入格式

The input consists of multiple test cases. The first line contains an integer tt (1≤t≤10001 \le t \le 1000) — the number of test cases.

The first line of each test case contains three integers nn, ll, and rr (2≤n≤2⋅1052 \le n \le 2 \cdot 10^5; nn is even; 0≤l,r≤n0 \le l, r \le n; l+r=nl+r=n) — the total number of socks, and the number of left and right socks, respectively.

The next line contains nn integers cic_i (1≤ci≤n1 \le c_i \le n) — the colors of the socks. The first ll socks are left socks, while the next rr socks are right socks.

It is guaranteed that the sum of nn across all the test cases will not exceed 2⋅1052 \cdot 10^5.

输入包含多个测试用例。第一行包含一个整数 tt(1≤t≤10001 \le t \le 1000),表示测试用例的数量。

每个测试用例的第一行包含三个整数 nn、ll 和 rr(2≤n≤2⋅1052 \le n \le 2 \cdot 10^5;nn 为偶数;0≤l,r≤n0 \le l, r \le n;且 l+r=nl+r=n),分别表示袜子的总数、左袜子数量和右袜子数量。

下一行包含 nn 个整数 cic_i(1≤ci≤n1 \le c_i \le n),表示每只袜子的颜色。其中前 ll 只袜子为左袜子,后 rr 只袜子为右袜子。

保证所有测试用例中 nn 的总和不超过 2⋅1052 \cdot 10^5。

输出格式

For each test case, print one integer — the minimum cost for Phoenix to make n/2n/2 matching pairs. Each sock must be included in exactly one matching pair.

对于每个测试用例,输出一个整数——凤凰制作 n/2n/2 对匹配袜子的最小花费。每只袜子必须且仅能出现在一对匹配中。

输入输出样例

  • 输入#1

    4
    6 3 3
    1 2 3 2 2 2
    6 2 4
    1 1 2 2 2 2
    6 5 1
    6 5 4 3 2 1
    4 0 4
    4 4 4 3

    输出#1

    2
    3
    5
    3

说明/提示

In the first test case, Phoenix can pay 22 dollars to:

  • recolor sock 11 to color 22
  • recolor sock 33 to color 22

There are now 33 matching pairs. For example, pairs (1,4)(1, 4), (2,5)(2, 5), and (3,6)(3, 6) are matching.

In the second test case, Phoenix can pay 33 dollars to:

  • turn sock 66 from a right sock to a left sock
  • recolor sock 33 to color 11
  • recolor sock 44 to color 11

There are now 33 matching pairs. For example, pairs (1,3)(1, 3), (2,4)(2, 4), and (5,6)(5, 6) are matching.

在第一个测试用例中,Phoenix 可以支付 22 美元来:

  • 将袜子 11 重新染色为颜色 22
  • 将袜子 33 重新染色为颜色 22

此时共有 33 对匹配的袜子。例如,对 (1,4)(1, 4)、(2,5)(2, 5) 和 (3,6)(3, 6) 均为匹配对。

在第二个测试用例中,Phoenix 可以支付 33 美元来:

  • 将袜子 66 从右袜变为左袜
  • 将袜子 33 重新染色为颜色 11
  • 将袜子 44 重新染色为颜色 11

此时共有 33 对匹配的袜子。例如,对 (1,3)(1, 3)、(2,4)(2, 4) 和 (5,6)(5, 6) 均为匹配对。

输入解题思路,AI测评打分。不知道怎么写?

首页