Jessica's Reading Problem
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 7467   Accepted: 2369

Description

Jessica's a very lovely girl wooed by lots of boys. Recently she has a problem. The final exam is coming, yet she has spent little time on it. If she wants to pass it, she has to master all ideas included in a very thick text book. The author of that text book, like other authors, is extremely fussy about the ideas, thus some ideas are covered more than once. Jessica think if she managed to read each idea at least once, she can pass the exam. She decides to read only one contiguous part of the book which contains all ideas covered by the entire book. And of course, the sub-book should be as thin as possible.

A very hard-working boy had manually indexed for her each page of Jessica's text-book with what idea each page is about and thus made a big progress for his courtship. Here you come in to save your skin: given the index, help Jessica decide which contiguous part she should read. For convenience, each idea has been coded with an ID, which is a non-negative integer.

Input

The first line of input is an integer P (1 ≤ P ≤ 1000000), which is the number of pages of Jessica's text-book. The second line contains P non-negative integers describing what idea each page is about. The first integer is what the first page is about, the second integer is what the second page is about, and so on. You may assume all integers that appear can fit well in the signed 32-bit integer type.

Output

Output one line: the number of pages of the shortest contiguous part of the book which contains all ideals covered in the book.

Sample Input

5
1 8 8 8 1

Sample Output

2
尺取法,O(n)
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 100001
#define eps 1e-9
const int inf=0x7fffffff; //无限大
int p;
int a[maxn];
void solve()
{
set<int> all;
for(int i=;i<p;i++)
{
all.insert(a[i]);
}
int n=all.size();
int s=,t=,num=;
map<int,int> count;
int res=p;
for(;;)
{
while(t<p&&num<n)
{
if(count[a[t++]]++==)
{
num++;
}
}
if(num<n)
break;
res=min(res,t-s);
if(--count[a[s++]]==)
num--;
}
cout<<res<<endl;
} int main()
{
cin>>p;
for(int i=;i<p;i++)
scanf("%d",&a[i]);
solve();
}

最新文章

  1. .NET 串口通信
  2. oracle 做算法 数据为空时,默认为0
  3. python-类和对象(属性、方法)的动态绑定
  4. php引用计数与变量引用
  5. Storyboard、Nib文件和代码来实现UI的利与弊
  6. windows如何安装scrapy
  7. RxSwift 系列(二) -- Subject
  8. 表单提交 fastadmin form
  9. js之 单例模式
  10. PAT甲题题解-1130. Infix Expression (25)-中序遍历
  11. CSS魔法(三)浮动、相对定位、绝对定位
  12. Web侦察工具HTTrack (爬取整站)
  13. JAVA8流操作
  14. VMware用于Site Recovery Manager 5的vSphere Replication功能一览
  15. 算法笔记_233:二阶魔方旋转(Java)
  16. V-rep学习笔记:Reflexxes Motion Library 3
  17. chrom调试
  18. [BZOJ1791][IOI2008]Island岛屿(环套树DP)
  19. 如何理解 Python 中的__init__
  20. angular与avalon对复杂对象的修改

热门文章

  1. RestTemplate中文乱码问题(spring-web3.0.7版本)
  2. 网络协议之NAT穿透
  3. jersey 过滤器名称绑定的问题 NameBinding Provider
  4. mdb数据库文件如何导入Microsoft SQL Server 2008中
  5. SQL 根据生日和日期计算年龄
  6. CCF CSP 201412-2 Z字形扫描
  7. mysql 删除重复项
  8. linux保证程序单实例运行
  9. 8-4 奖品的价值 uva11491(贪心)
  10. mysql (主从复制)(proxy , Amoeba)