#include #include

using namespace std; const int N = 100000; int a[N],s[N];

int main() { int p,k; scanf("%d",&p); for(int i=0;i<p;i++) { scanf("%d",&a[i]); } scanf("%d",&k); int l=0,r=0,sum=0,ans=0x3f3f3f3f; while(r<p) { s[a[r]]++; if(s[a[r]]==1)sum++; while(sum==k) { ans=min(ans,r-l+1); s[a[l]]--; if(s[a[l]]==0)sum--; l++; } r++; } printf("%d\n",ans); return 0; }

C++ 尺取法求最短连续页数:知识点覆盖问题

原文地址: https://www.cveoy.top/t/topic/opVf 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录