#5#6wa求助
  • 板块P1638 逛画展
  • 楼主chiemi520
  • 当前回复1
  • 已保存回复1
  • 发布时间2022/9/2 22:37
  • 上次更新2023/10/27 12:46:32
查看原帖
#5#6wa求助
730263
chiemi520楼主2022/9/2 22:37
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
int a[1000010];
int cnt[2002];
int main() {
    int n,m;
    scanf("%d%d",&n,&m);
    for (int i=1;i<=n;i++){
        scanf("%d",&a[i]);
        
    }
    int w = 0;
    int l=1,r=0,al=0,ar=n+1;
    while(l+m<n){
        while(w<m&&r<=n){//注意re
            r++;
            if(cnt[a[r]]==0)w++;
            cnt[a[r]]++;
            
            
        }
        if(w==m) if(r-l<ar-al) {ar=r;al=l;}//don't forget 'w==m',to avoid the situation that only r>n,but the w is not accomplished.
        
        cnt[a[l]]--;
        if(cnt[a[l]]==0)w--;
        l++;
        if(r>n)break;
        
    }
    
    printf("%d %d",al,ar);
    return 0;
}

2022/9/2 22:37
加载中...