C. Ivan and Powers of Two
time limit per test

0.5 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Ivan has got an array of n non-negative integers a1, a2, ..., an. Ivan knows that the array is sorted in the non-decreasing order.

Ivan wrote out integers 2a1, 2a2, ..., 2an on a piece of paper. Now he wonders, what minimum number of integers of form 2b (b ≥ 0)need to be added to the piece of paper so that the sum of all integers written on the paper equalled 2v - 1 for some integer v (v ≥ 0).

Help Ivan, find the required quantity of numbers.

Input

The first line contains integer n (1 ≤ n ≤ 105). The second input line contains n space-separated integers a1, a2, ..., an(0 ≤ ai ≤ 2·109). It is guaranteed that a1 ≤ a2 ≤ ... ≤ an.

Output

Print a single integer — the answer to the problem.

Examples
input
4
0 1 1 1
output
0
input
1
3
output
3

set数据结构的应用,
#include <set>
一个集合(set)是一个容器,它其中所包含的元素的值是唯一的。
集和多集的区别是:set支持唯一键值,set中的值都是特定的,而且只出现一次;而multiset中可以出现副本键,同一值可以出现多次。
 
begin() 返回指向第一个元素的迭代器
clear() 清除所有元素
count() 返回某个值元素的个数
empty() 如果集合为空,返回true(真)
end() 返回指向最后一个元素之后的迭代器,不是最后一个元素
equal_range() 返回集合中与给定值相等的上下限的两个迭代器
erase() 删除集合中的元素
find() 返回一个指向被查找到元素的迭代器,如果没找到则返回end()
get_allocator() 返回集合的分配器
insert() 在集合中插入元素
lower_bound() 返回指向大于(或等于)某值的第一个元素的迭代器
key_comp() 返回一个用于元素间值比较的函数
max_size() 返回集合能容纳的元素的最大限值
rbegin() 返回指向集合中最后一个元素的反向迭代器
rend() 返回指向集合中第一个元素的反向迭代器
size() 集合中元素的数目
swap() 交换两个集合变量
upper_bound() 返回大于某个值元素的迭代器
value_comp() 返回一个用于比较元素间的值的函数
 
#include<iostream>
#include<cstdio>
#include<set>
using namespace std; set<int> s; int main()
{
int n,maxn=;
scanf("%d",&n);
for(int i=;i<n;i++)
{
int num;
scanf("%d",&num);
while(s.count(num))
{
s.erase(num);
num++;
}
s.insert(num);
maxn=max(maxn,num);
}
printf("%d\n",maxn-s.size()+);
return ;
}

codeforces_305C_STLset的更多相关文章

  1. Team Foundation 中的错误和事件消息

    Visual Studio Team System Team Foundation 中的错误和事件消息 Team Foundation 通过显示错误消息和事件消息来通知您操作成功以及操作失败.一部分错 ...

随机推荐

  1. react 项目实战(六)提取布局组件

    重复代码是混乱的根源!,本篇文章我们来继续消灭重复代码. 目标 细心的同学应该能发现:每一个Page组件(/src/pages下的组件)的render方法都拥有相似的jsx结构,比如: render ...

  2. RAD 极速应用开发 Spring ROO 入门样例

    官网                                      http://projects.spring.io/spring-roo/ Spring ROO in action   ...

  3. SDUT--找朋友(BFS&amp;&amp;DFS)

    找朋友 Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描写叙述 X,作为户外运动的忠实爱好者,总是不想呆在家里.如今,他想把死宅Y从家 ...

  4. Canny算法源码,欢迎交流

    http://blog.csdn.net/jianxiong8814/article/details/1563109 http://blog.csdn.net/assuper/article/deta ...

  5. BZOJ 3041 水叮当的舞步

    3041: 水叮当的舞步 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 120  Solved: 67[Submit][Status][Discuss ...

  6. 【codevs1306】广播操的游戏

    求字符串内的非空子串的数量 后缀数组!!! #include<algorithm> #include<cstdlib> #include<cstring> #inc ...

  7. CSS总结01

    1 CSS 的作用是? 2 如何引入 CSS 样式? 3 CSS 选择器的基本类型和复合选择器分别是? 4 字体.背景.列表和链接和鼠标的属性有哪些? 5 如何理解盒子模型? 6 浮动的方式有哪些,如 ...

  8. 【Android】Android输入子系统【转】

    本文转载自:https://www.cnblogs.com/lcw/p/3506110.html Linux输入子系统回顾 1:为什么要回顾linux输入子系统?这个问题后面自然就知道了 1.linu ...

  9. ADT20 混淆编译

    注意:一定要 android代码混淆,整了两天怎么也弄不去来,百度翻遍了也都是怎么配置cfg文件,怎么混淆成功的喜悦,我就气死了,怎么都不成功.真是气死了,不过功夫不负有心人,终究还是弄出来了. 不能 ...

  10. JSP-Runoob:JSP 结构

    ylbtech-JSP-Runoob:JSP 结构 1.返回顶部 1. JSP 结构 网络服务器需要一个 JSP 引擎,也就是一个容器来处理 JSP 页面.容器负责截获对 JSP 页面的请求.本教程使 ...