poj3320 Jessica's Reading Problem(尺取思路+STL)

时间:2023-03-09 19:41:25
poj3320 Jessica's Reading Problem(尺取思路+STL)

https://vjudge.net/problem/POJ-3320

尺取法,要想好组织方式。

又被卡了cin。。

#include<iostream>
#include<cstdio>
#include<queue>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<stack>
#include<map>
#include<set>
#define lson l, m, rt<<1
#define rson m+1, r, rt<<1|1
#define INF 0x3f3f3f3f
typedef unsigned long long ll;
using namespace std;
set<int> st;
map<int, int> mp;
int a[];
int main()
{ int n;
scanf("%d", &n);
for(int i = ; i < n; i++){
scanf("%d", &a[i]);
st.insert(a[i]);
mp[a[i]] = ;
}
int m = st.size();
int s=, t=, num=, ans = INF;
while(){
while(t < n&&num < m){//判断种类是否都涵盖
if(mp[a[t++]]++ == ){//如果是该类知识点的第一个
num++;//种类++
}
}
if(num < m) break;
ans = min(ans, t-s);
if(--mp[a[s++]] == ){//后判断a[s]的类的个数--后是否为0
num--;//种类--
}
}
printf("%d\n", ans);
return ;
}