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. [Qt总结篇]终端远程升级client

    环境: QT4.8.5 for Windows(Qt Creator+MinGW) 一.写在前面: 1.深度:鉴于C/C++的功底还远远不足,个人主要精力还是学习C/C++,所以没打算继续深入研究Qt ...

  2. HDU 1047 Integer Inquiry 大数相加 string解法

    本题就是大数相加,题目都不用看了. 只是注意的就是HDU的肯爹输出,好几次presentation error了. 还有个特殊情况,就是会有空数据的输入case. #include <stdio ...

  3. 【Struts2五】ValueStack以及ognl表达式二(经常使用标签)

    Ognl经常使用标签:   1.s:debug       假设把该标签放入到s:iterator中能够看到当前正在迭代的元素的状态    2.s:property       1.输出       ...

  4. iOS CMSampleBuffer deep copy

    extension CVPixelBuffer { func copy() -> CVPixelBuffer { precondition(CFGetTypeID(self) == CVPixe ...

  5. web 开发之js---js 实现文本高亮

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html> <head ...

  6. DSPC6748中某问题的解决方式

    因为之前没有做过DSP相关的开发,属于菜鸟中的菜鸟.出现故障后.不知道从哪方面来解决这些小问题. 开发环境:CCS5.5.0 开发板:TI公司的TMS320C6748 问题: 控制台出现初始化结束后多 ...

  7. leetcode第一刷_Search in Rotated Sorted Array

    旋转数组的查找问题.从头開始扫一遍.O(N)的复杂度,一般也能过,甚至先排序下面,再二分都能过.只是这道题的目的当然不在于此. 想一下旋转之后对我们的查找产生了什么影响.假设没旋转过,我们直接比較ta ...

  8. go11---方法method

    package main /* 方法method Go 中虽没有class,但依旧有method 通过显示说明receiver来实现与某个类型的组合 只能为同一个包中的类型定义方法 Receiver ...

  9. sql 2005 win7 64 数据引擎

    有个箭头,下拉,选择服务器名(就是本机的名称),如果没有就选择浏览更多,看能搜索出不还没的话就手动输入localhost

  10. ROUND function and arithmetic overflow

    遇到如下错误 Arithmetic overflow error converting expression to data type numeric. ), ); https://stackover ...