CF780A.Andryusha and Socks
入门
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Andryusha is an orderly boy and likes to keep things in their place.
Today he faced a problem to put his socks in the wardrobe. He has n distinct pairs of socks which are initially in a bag. The pairs are numbered from 1 to n. Andryusha wants to put paired socks together and put them in the wardrobe. He takes the socks one by one from the bag, and for each sock he looks whether the pair of this sock has been already took out of the bag, or not. If not (that means the pair of this sock is still in the bag), he puts the current socks on the table in front of him. Otherwise, he puts both socks from the pair to the wardrobe.
Andryusha remembers the order in which he took the socks from the bag. Can you tell him what is the maximum number of socks that were on the table at the same time?
安德柳沙是个做事有条理的男孩,喜欢把东西放在该放的位置。
今天,他遇到了一个难题:要把自己的袜子放进衣柜里。他有 n 双互不相同的袜子,最初都装在一个袋子里。这 n 双袜子编号为 1 到 n。安德柳沙希望将成对的袜子放在一起,然后一起放进衣柜。他从袋中一只一只地取出袜子;对于每只取出的袜子,他都会检查其配对的那只袜子是否已经被取出了。如果尚未取出(即其配对袜子仍在袋中),他就把当前这只袜子放在自己面前的桌子上;否则(即其配对袜子已被取出),他就把这一对袜子一起放进衣柜。
安德柳沙记得自己从袋中取袜子的顺序。你能告诉他:在这一过程中,桌子上同时出现的袜子最多有多少只?
输入格式
The first line contains the single integer n (1 ≤ n ≤ 105) — the number of sock pairs.
The second line contains 2_n_ integers _x_1, _x_2, ..., x_2_n (1 ≤ x__i ≤ n), which describe the order in which Andryusha took the socks from the bag. More precisely, x__i means that the i-th sock Andryusha took out was from pair x__i.
It is guaranteed that Andryusha took exactly two socks of each pair.
第一行包含一个整数 n(1≤n≤105)——袜子对的数量。
第二行包含 2n 个整数 x1,x2,…,x2n(1≤xi≤n),描述了安德留沙从袋中取出袜子的顺序。更准确地说,xi 表示安德留沙第 i 次取出的袜子属于第 xi 对袜子。
保证安德留沙恰好取出了每对袜子中的两只。
输出格式
Print single integer — the maximum number of socks that were on the table at the same time.
输出一个整数——桌子上的袜子数量的最大值。
输入输出样例
输入#1
1 1 1
输出#1
1
输入#2
3 2 1 1 3 2 3
输出#2
2
说明/提示
In the first example Andryusha took a sock from the first pair and put it on the table. Then he took the next sock which is from the first pair as well, so he immediately puts both socks to the wardrobe. Thus, at most one sock was on the table at the same time.
In the second example Andryusha behaved as follows:
- Initially the table was empty, he took out a sock from pair 2 and put it on the table.
- Sock (2) was on the table. Andryusha took out a sock from pair 1 and put it on the table.
- Socks (1, 2) were on the table. Andryusha took out a sock from pair 1, and put this pair into the wardrobe.
- Sock (2) was on the table. Andryusha took out a sock from pair 3 and put it on the table.
- Socks (2, 3) were on the table. Andryusha took out a sock from pair 2, and put this pair into the wardrobe.
- Sock (3) was on the table. Andryusha took out a sock from pair 3 and put this pair into the wardrobe.
Thus, at most two socks were on the table at the same time.
在第一个例子中,安德留沙从第一双袜子中取出一只并放在桌子上。接着他取出的下一只袜子也来自第一双,因此他立即把这一双袜子都收进衣柜。于是,在任意时刻,桌面上最多只有一只袜子。
在第二个例子中,安德留沙的操作如下:
- 初始时桌面为空,他从第 2 双袜子中取出一只并放在桌子上。
- 桌面上有袜子 (2)。安德留沙从第 1 双袜子中取出一只并放在桌子上。
- 桌面上有袜子 (1, 2)。安德留沙又从第 1 双袜子中取出一只,于是将第 1 双袜子收进衣柜。
- 桌面上有袜子 (2)。安德留沙从第 3 双袜子中取出一只并放在桌子上。
- 桌面上有袜子 (2, 3)。安德留沙又从第 2 双袜子中取出一只,于是将第 2 双袜子收进衣柜。
- 桌面上有袜子 (3)。安德留沙又从第 3 双袜子中取出一只,于是将第 3 双袜子收进衣柜。
于是,在任意时刻,桌面上最多有两只袜子。
输入解题思路,AI测评打分。不知道怎么写?