(Winter Camp) survey

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.