0
点赞
收藏
分享

微信扫一扫

逛画展


题目:

逛画展_算法

#include <iostream>
#include <cmath>
#include <cstdio>
using namespace std;
int pos[1000000];
int main()
{
long long n,m;
cin>>n>>m;
for(int i=1;i<=n;i++){
scanf("%d",&pos[i]);
}
int ans=n+1;
int rea,reb,count=1,a=1,b=1;
int master[10010]={0};
master[pos[1]]=1;
while(a<=b&&b<=n){
if(count==m){
if(ans>b-a+1){
ans=b-a+1;
rea=a;
reb=b;
}
master[pos[a]]--;
if(master[pos[a]]==0) count--;
a++;
}
else{
b++;
master[pos[b]]++;
if(master[pos[b]]==1) count++;
}
}
cout<<rea<<" "<<reb<<endl;
return 0;
}


举报

相关推荐

0 条评论