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

Source

POJ Monthly--2007.08.05, Jerry
 
 
 
题目大意:

离散化+尺取乱搞

 program rrr(input,output);
var
a,b,c:array[..]of longint;
n,m,i,j,ans,l,r,mid:longint;
function min(a,b:longint):longint;
begin
if a<b then exit(a) else exit(b);
end;
procedure sort(q,h:longint);
var
i,j,x,t:longint;
begin
i:=q;j:=h;x:=b[(i+j)>>];
repeat
while b[i]<x do inc(i);
while x<b[j] do dec(j);
if i<=j then
begin
t:=b[i];b[i]:=b[j];b[j]:=t;
inc(i);dec(j);
end;
until i>j;
if j>q then sort(q,j);
if i<h then sort(i,h);
end;
function find(x:longint):longint;
begin
l:=;r:=m;
while l<r- do
begin
mid:=(l+r)>>;
if b[mid]>x then r:=mid- else l:=mid;
end;
if b[l]=x then exit(l) else exit(r);
end;
begin
assign(input,'r.in');assign(output,'r.out');reset(input);rewrite(output);
readln(n);
for i:= to n do begin read(a[i]);b[i]:=a[i]; end;
sort(,n);
m:=;for i:= to n do if b[i]<>b[i-] then begin inc(m);b[m]:=b[i]; end;
for i:= to n do a[i]:=find(a[i]);
fillchar(c,sizeof(c),);i:=;
for j:= to n do
begin
inc(c[a[j]]);
if c[a[j]]= then inc(i);
if i=m then break;
end;
ans:=j;
for i:= to n do
begin
dec(c[a[i-]]);
while (j<n) and (c[a[i-]]=) do begin inc(j);inc(c[a[j]]); end;
if c[a[i-]]= then break;
ans:=min(ans,j-i+);
end;
write(ans);
close(input);close(output);
end.

poj3320 Jessica's Reading Problem的更多相关文章

  1. POJ3320 Jessica's Reading Problem(尺取+map+set)

    POJ3320 Jessica's Reading Problem set用来统计所有不重复的知识点的数,map用来维护区间[s,t]上每个知识点出现的次数,此题很好的体现了map的灵活应用 #inc ...

  2. POJ3320 Jessica's Reading Problem 2017-05-25 19:55 38人阅读 评论(0) 收藏

    Jessica's Reading Problem Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 12346   Accep ...

  3. poj3320 Jessica's Reading Problem(尺取思路+STL)

    https://vjudge.net/problem/POJ-3320 尺取法,要想好组织方式. 又被卡了cin.. #include<iostream> #include<cstd ...

  4. poj3061 Subsequence&&poj3320 Jessica's Reading Problem(尺取法)

    这两道题都是用的尺取法.尺取法是<挑战程序设计竞赛>里讲的一种常用技巧. 就是O(n)的扫一遍数组,扫完了答案也就出来了,这过程中要求问题具有这样的性质:头指针向前走(s++)以后,尾指针 ...

  5. POJ3320 Jessica's Reading Problem

    Bryce1010模板 #include <stdio.h> #include <string.h> #include <stdlib.h> #include &l ...

  6. 【二分】Jessica's Reading Problem

    [POJ3320]Jessica's Reading Problem Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 1309 ...

  7. Jessica's Reading Problem——POJ3320

    Jessica's Reading Problem——POJ3320 题目大意: Jessica 将面临考试,她只能临时抱佛脚的在短时间内将课本内的所有知识点过一轮,课本里面的P个知识点顺序混乱,而且 ...

  8. Greedy:Jessica's Reading Problem(POJ 3320)

    Jessica's Reading Problem 题目大意:Jessica期末考试临时抱佛脚想读一本书把知识点掌握,但是知识点很多,而且很多都是重复的,她想读最少的连续的页数把知识点全部掌握(知识点 ...

  9. POJ 3320 Jessica's Reading Problem

    Jessica's Reading Problem Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6001   Accept ...

随机推荐

  1. Tomcat学习(一)------部署Web应用方法总结

    Tomcat部署Web应用方法总结 在Tomcat中部署Java Web应用程序有两种方式:静态部署和动态部署. 在下文中$CATALINA_HOME指的是Tomcat根目录. 一.静态部署 静态部署 ...

  2. 利用Xilinx HLS实现LDPC译码器

    1. 概述 采用Xilinx HLS快速实现的部分并行,全流水的LDPC译码器. 环境:Vivado HLS 2018.2 码字:IEEE 802.16e 2/3A 算法:Min-Sum Algori ...

  3. [Unity Shader] 切线空间的法线贴图

    切线空间的法线贴图,可以这样理解: #纹理坐标是从0到1,它的坐标是x向右,y向下 #顶点坐标是从-1到-1,坐标是x向右,y向上 1 由表面上某点的切线Tangent.副切线Bitangent.法线 ...

  4. Python中格式化format()方法详解

    Python中格式化format()方法详解 Python中格式化输出字符串使用format()函数, 字符串即类, 可以使用方法; Python是完全面向对象的语言, 任何东西都是对象; 字符串的参 ...

  5. python数据分析系列(1)

    目录 python基础 python语言基础 Ipython的一些特性 Python语法基础 Python控制流 lambda表达式 Python的数据结构 元组 列表 字典 集合 列表.集合.字典推 ...

  6. excel窗口独立显示/单独显示

    天赋异禀的亲,一看就懂!

  7. oracle查看用户表

    select table_name from user_tables;

  8. Linux读书笔记第一、二章

    第一章    Linux内核简介 1.1Unix历史 Unix特点:1.很简洁 2.所有东西都被当成文件对待 3.Unix内核和相关的系统工具软件都是用C语言编写而成 4.进程创建非常迅速 1.2追寻 ...

  9. 20162325 金立清 S2 W7 C16

    20162325 2017-2018-2 <程序设计与数据结构>第7周学习总结 教材学习内容概要 树是非线性结构,其元素组织为一个层次结构 树的度表示树种任意结点的最大子结点数 有m个元素 ...

  10. SpringMVC 常用注释

    @Controller  Controller控制器是通过服务接口定义的提供访问应用程序的一种行为 @Repository  Dao层的标志 @RequestMapping  标注控制层函数的访问路径 ...