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
  1. 4
    0 1 1 1
output
  1. 0
input
  1. 1
    3
output
3

  1. 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() 返回一个用于比较元素间的值的函数
 
  1. #include<iostream>
  2. #include<cstdio>
  3. #include<set>
  4. using namespace std;
  5.  
  6. set<int> s;
  7.  
  8. int main()
  9. {
  10. int n,maxn=;
  11. scanf("%d",&n);
  12. for(int i=;i<n;i++)
  13. {
  14. int num;
  15. scanf("%d",&num);
  16. while(s.count(num))
  17. {
  18. s.erase(num);
  19. num++;
  20. }
  21. s.insert(num);
  22. maxn=max(maxn,num);
  23. }
  24. printf("%d\n",maxn-s.size()+);
  25. return ;
  26. }

codeforces_305C_STLset的更多相关文章

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

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

随机推荐

  1. 基于MFC的一个简单计算器

    写一个简单的计算器并不是什么很难的事,主要目的是要通过这个程序来学习和分析其中的核心算法.这个简易计算器的核心部分就是对输入的表达式的正确性判断与求值,其中包括对表达式的解析.中缀表达式转后缀表达式. ...

  2. eclipse中j2ee(struts2)部署及相关问题释疑

    1.eclipse中进行web项目开发时.部署的时候和利用myeclipse部署时有非常大不同,由于在myeclipse的工具栏中有一个部署button.而且在myeclipse的preference ...

  3. CI知识:GitLab

    Gitlab简介 GitLab 是一个用于仓库管理系统的开源项目,使用Git作为代码管理工具,并在此基础上搭建起来的web服务. 可通过Web界面进行访问公开的或者私人项目.它拥有与Github类似的 ...

  4. MVC4中给TextBoxFor设置默认值和属性(同时设置js事件)

    例如:(特别注意在设置初始值的时候 Value 中的V要大写) @Html.TextBoxFor(model => model.CustomerCode, new { Value="  ...

  5. 万一的Delphi消息教程

    http://www.cnblogs.com/del/category/134064.html

  6. kendo datepicker汉化

    kendo grid 支持多语言,包括的语言有非常多种.一般默认情况是使用en,可是对于国内市场的话我们须要使用汉字.不墨迹了.     <link href="http://cdn. ...

  7. H264 介绍[1]

    频编解码技术有两套标准,国际电联(ITU-T)的标准H.261.H.263.H.263+等:还有ISO 的MPEG标准Mpeg1.Mpeg2.Mpeg4等等.H.264/AVC是两大组织集合H.263 ...

  8. bzoj 2067 [ Poi 2004 ] SZN —— 二分

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2067 问题1:贪心考虑,应该是每个点的儿子尽量两两配对,如果剩一个就和自己合并向上,所以 a ...

  9. ELK Stack总结

    目录 ELK Stack 介绍 Elasticsearch 概念1(基础) CRUD基本用法 概念2(文本解析器) 查询 分析/聚合 概念3(架构原理的补充) Logstash基础 Kibana的数据 ...

  10. bzoj 1704: [Usaco2007 Mar]Face The Right Way 自动转身机【贪心+差分】

    首先O(n^3)的贪心很好想,就是枚举k然后从前往后扫,扫到反就翻转区间 然后考虑优化掉翻转区间维,就是搞成差分的形式,在翻转区间的尾部打上标记,再用一个变量维护当前的翻转次数,加到当前状态上来判断是 ...