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. 菜鸟vimer成长记——第1章、统一概念

    不管学什么技术,我都深信概念是最重要的.是影响整个学习轨迹,决定能在这个技术领域高度. 当然如果你现在的目的不是在学习而在于解决问题(很多人不愿意承认,或者没发现),那概念就暂时没那么重要了. 目的 ...

  2. 关于判断用户输入的是不是int类型,这次没有正则表达式

    末尾没有目的地的出租车,污点证人禁止入内!!! 不同的尝试有不同的方法 关于int类型的判断,我尝试了这么一个方法,可行,只是笨 正则表达式我没有搞清楚,没办法给大家讲解,欢迎各位明白人讲解,或者是我 ...

  3. Spring学习(十五)----- Spring AOP通知实例 – Advice

    Spring AOP(面向方面编程)框架,用于在模块化方面的横切关注点.简单得说,它只是一个拦截器拦截一些过程,例如,当一个方法执行,Spring AOP 可以劫持一个执行的方法,在方法执行之前或之后 ...

  4. SQL语句汇总(终篇)—— 表联接与联接查询

    既然是最后一篇那就不能只列出些干枯的标准语句,更何况表联接也是SQL中较难的部分,所以此次搭配题目来详细阐述表联接. 上一篇博文说到相关子查询效率低下,那我们怎么能将不同表的信息一起查询出来呢?这就需 ...

  5. JavaScript 数组——filter()、map()、some()、every()、forEach()、lastIndexOf()、indexOf()

    filter():   语法: var filteredArray = array.filter(callback[, thisObject]); 参数说明: callback: 要对每个数组元素执行 ...

  6. Asp.Net Form验证不通过,重复登录(.net4,4.5form验证兼容性问题)

    问题产生根源: 当然,其实应该需要保持线上所有机器环境一致!可是,写了一个小程序.使用的是4.5,aysnc/await实在太好用了,真心不想把代码修改回去. so,动了念头,在这台服务器上装个4.5 ...

  7. Nginx应用场景

    1. Nginx应用场景 1)http服务器.Nginx可以独立的提供http服务,可以做网页静态服务器(也就是将静态文件放到nginx目录下,通过nginx来访问就ok)   2)虚拟主机,可以在一 ...

  8. 【LeetCode算法题库】Day5:Roman to Integer & Longest Common Prefix & 3Sum

    [Q13] Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M. Symbol Valu ...

  9. 为 GlusterFS 设计新的xlator (编译及调用过程分析)

    GlusterFS 是一个开源的网络分布式文件系统,前一阵子看了一点GlusterFS(Gluster)的代码,修改了部分代码,具体是增加了一个定制的xlator,简单记录一下. Gluster与xl ...

  10. 机器人平台框架Yarp - Yet another robot platform

    简介 ROS有强大和易用的特性,用的人很多,目前已经推出2.0版本,有相关的官网和论坛.然而其缺点也比较明显. 只能基于Ubuntu系统,且一个ROS版本只能对应一个具体的Ubuntu版本    通信 ...