AC日记——Andryusha and Socks Codeforces 780a
2 seconds
256 megabytes
standard input
standard output
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?
The first line contains the single integer n (1 ≤ n ≤ 105) — the number of sock pairs.
The second line contains 2n integers x1, x2, ..., x2n (1 ≤ xi ≤ n), which describe the order in which Andryusha took the socks from the bag. More precisely, xi means that the i-th sock Andryusha took out was from pair xi.
It is guaranteed that Andryusha took exactly two socks of each pair.
Print single integer — the maximum number of socks that were on the table at the same time.
1
1 1
1
3
2 1 1 3 2 3
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.
#include <cstdio>
#include <iostream> #define maxn 100005 using namespace std; int n,pos,ans,pos_; char Cget; bool if_[maxn]; inline void in(int &now)
{
now=,Cget=getchar();
while(Cget>''||Cget<'') Cget=getchar();
while(Cget>=''&&Cget<='')
{
now=now*+Cget-'';
Cget=getchar();
}
} int main()
{
in(n);
for(int i=;i<=(n<<);i++)
{
in(pos_);
if(!if_[pos_])
{
if_[pos_]=true;
pos++;
ans=max(ans,pos);
}
else pos--;
}
cout<<ans;
return ;
}
AC日记——Andryusha and Socks Codeforces 780a的更多相关文章
- AC日记——Andryusha and Colored Balloons codeforces 780c
C - Andryusha and Colored Balloons 思路: 水题: 代码: #include <cstdio> #include <cstring> #inc ...
- AC日记——Dynamic Problem Scoring codeforces 807d
Dynamic Problem Scoring 思路: 水题: 代码: #include <cstdio> #include <cstring> #include <io ...
- AC日记——Sign on Fence Codeforces 484e
E. Sign on Fence time limit per test 4 seconds memory limit per test 256 megabytes input standard in ...
- AC日记——Sagheer, the Hausmeister codeforces 812b
812B - Sagheer, the Hausmeister 思路: 搜索: 代码: #include <cstdio> #include <cstring> #includ ...
- AC日记——Sagheer and Crossroads codeforces 812a
812A - Sagheer and Crossroads 思路: 模拟: 代码: #include <cstdio> #include <cstring> #include ...
- AC日记——Is it rated? codeforces 807a
Is it rated? 思路: 水题: 代码: #include <cstdio> #include <cstring> using namespace std; ],b[] ...
- Ac日记——Distances to Zero codeforces 803b
803B - Distances to Zero 思路: 水题: 代码: #include <cstdio> #include <cstring> #include <i ...
- AC日记——Mice and Holes codeforces 797f
797F - Mice and Holes 思路: XXYXX: 代码: #include <cmath> #include <cstdio> #include <cst ...
- AC日记——Roma and Poker codeforces 803e
803E - Roma and Poker 思路: 赢或输或者平的序列: 赢和平的差的绝对值不得超过k: 结束时差的绝对值必须为k: 当“?”时可以自己决定为什么状态: 输出最终序列或者NO: dp( ...
随机推荐
- 《零基础入门学习Python》【第一版】视频课后答案第001讲
测试题答案: 0. Python 是什么类型的语言? Python是脚本语言 脚本语言(Scripting language)是电脑编程语言,因此也能让开发者藉以编写出让电脑听命行事的程序.以简单的方 ...
- Pyhon从入门到致命
第一章 基础 1.python2和python3的区别 2.数据类型 2.1 int 整型 2.2 str 字符串不可变类型 2.3 bool 布尔类型 2.4 list 列表 2.5 tuple 元 ...
- jmeter接口测试 ——学习笔记
JMETER常用操作 1.jmeter做http脚本 Http请求页面内容介绍 添加cookie 线程组-添加-配置元件--HTTP Cookie管理器 添加权限验证 不能使用普通用户修改学生金币,接 ...
- LeetCode(23)Merge k Sorted Lists
题目 Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity ...
- Java学习——面对对象的思想入门
本文是看过<head first Java>之后的一点感悟,写点东西帮忙以后回忆,Java目前在我的工作中用到还不多,而我又对面对对象的编程非常的感兴趣.曾经在MFC平台上写过 ...
- LA 7072 Signal Interference 计算几何 圆与多边形的交
题意: 给出一个\(n\)个点的简单多边形,和两个点\(A, B\)还有一个常数\(k(0.2 \leq k < 0.8)\). 点\(P\)满足\(\left | PB \right | \l ...
- luogu2153 [SDOI2009]晨跑
要想限制流量,总要想着拆点. #include <iostream> #include <cstring> #include <cstdio> #include & ...
- 25、Base64
Base64要求把每三个8Bit的字节转换为四个6Bit的字节(3*8 = 4*6 = 24),然后把6Bit再添两位高位0,组成四个8Bit的字节,也就是说,转换后的字符串理论上将要比原来的长1/3 ...
- 使用 D8 分析 javascript 如何被 V8 引擎优化的
在上一篇文章中我们讲了如何使用 GN 编译 V8 源码,文章最后编译完成的可执行文件并不是 V8,而是 D8.这篇我们讲一下如何使用 D8 调试 javascript 代码. 如果没有 d8,可以使用 ...
- TOJ4277: Sequence 组合数学
4277: Sequence Time Limit(Common/Java):2000MS/6000MS Memory Limit:65536KByte Total Submit: 39 ...