Investigation
Time limit: 1 Sec memory limit: MB
Submitted: 10 Solution:
Submitted State [Discussion Version]
Title Description Ezio As an assassin, investigative intelligence is an essential part, such as the target of recent activities such as the arrangement of information is very useful.
Ezio now has a survey list of n individuals, each with a number, numbered between 1 and M, the number of which is recorded by this person is related to which information, Ezio now to investigate 1 to m all intelligence, each piece of information only need to investigate the information related to a person can, due to the time relationship, Ezio wanted to investigate a continuous segment of the population and investigate as few people as possible. Enter a total of two lines, the first line two number n,m
The second row n number of number I is the number of the first person. Each of the two numbers is separated by a space, with no spaces at the end. Outputs a number that satisfies the minimum number of people for the condition. Data is guaranteed to be solvable. Sample input
7 66 1 2 4 4 5 3
Sample output
7
Tips
Data range
n<=1000000 m<=n
"Analysis" double pointer
#include <iostream>#include<cstring>#include<cstdio>#include<algorithm>#include<cmath>#include<string>#include<map>#include<stack>#include<queue>#include<vector>#defineINF 2e9#defineMet (b) memset (a,b,sizeof a)typedefLong Longll;using namespacestd;Const intN = 1e6+5;Const intM = 4e5+5;intn,m;intL=0, r=0;intcnt[n],sum=0, ans=inf;intA[n];intMain () {scanf ("%d%d",&n,&m); for(intI=0; i<n;i++) {scanf ("%d",&A[i]); } for(intI=0; i<n;i++) {Cnt[a[i]]++; R=i; if(cnt[a[i]]==1) sum++; if(sum>=m) { for(intj=l;j<=r;j++) {Cnt[a[j]]--; if(!Cnt[a[j]]) {ans=min (r-j+1, ans); //printf ("i=%d j=%d ans=%d l=%d r=%d\n", i,j,ans,l,r);l=j+1; Sum--; Break; } }}} printf ("%d\n", ans); return 0;}
(Winter Camp) survey