[推销博客](https://foreverlasting1202.github.io/2019/08/27/CF1208%E9%A2%98%E8%A7%A3/)
### B Uniqueness
题意:给一个长度为$n$的序列,最多可以去掉一个区间$[l,r]$,需要去掉之后满足每个数只出现一次,求$r-l+1$的最小值。$1\leq n\leq 2000,1\leq a_i\leq 10^9$
做法:枚举左端点,单调扫过右端点,用$map$维护一下一个数的出现次数,为$1$就合法,复杂度$O(n^2logn)$。
code:
```cpp
//2019.8.24 by ljz
//email
[email protected]
//if you find any bug in my code
//please tell me
#include<bits/stdc++.h>
using namespace std;
#define res register int
#define LL long long
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f
#define unl __int128
#define eps 5.6e-8
#define RG register
#define db double
#define pc(x) __builtin_popcount(x)
typedef pair<int,int> Pair;
#define mp make_pair
#define fi first
#define se second
#define pi acos(-1.0)
#define pb push_back
#define ull unsigned LL
#define gc getchar
//inline char gc() {
// static char buf[100000],*p1,*p2;
// return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
//}
inline int read() {
res s=0,ch=gc();
while(ch<'0'||ch>'9')ch=gc();
while(ch>='0'&&ch<='9')s=s*10+ch-'0',ch=gc();
return s;
}
//inline int read() {
// res s=0,ch=gc(),w=1;
// while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=gc();}
// while(ch>='0'&&ch<='9')s=s*10+ch-'0',ch=gc();
// return s*w;
//}
//inline LL Read() {
// RG LL s=0;
// res ch=gc();
// while(ch<'0'||ch>'9')ch=gc();
// while(ch>='0'&&ch<='9')s=s*10+ch-'0',ch=gc();
// return s;
//}
//inline LL Read() {
// RG LL s=0;
// res ch=gc(),w=1;
// while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=gc();}
// while(ch>='0'&&ch<='9')s=s*10+ch-'0',ch=gc();
// return s*w;
//}
//inline void write(RG unl x){
// if(x>10)write(x/10);
// putchar(int(x%10)+'0');
//}
inline void swap(res &x,res &y) {
x^=y^=x^=y;
}
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//clock_t start=clock();
//inline void ck(){
// if(1.0*(clock()-start)/CLOCKS_PER_SEC>0.1)exit(0);
//}
const int N=2e3+10;
namespace MAIN{
int n;
int a[N];
map<int,int> buc,vis;
int ans=inf;
inline void MAIN(){
n=read();
for(res i=1;i<=n;i++)a[i]=read();
for(res l=1;l<=n;l++){
res ret=0;
for(res i=1;i<=n;i++)buc[a[i]]=vis[a[i]]=0;
for(res i=1;i<=n;i++)buc[a[i]]++;
for(res i=1;i<=n;i++)if(buc[a[i]]>=2&&!vis[a[i]])ret++,vis[a[i]]=1;
// printf("%d\n",ret);
if(!ret){puts("0");return;}
for(res r=l;r<=n;r++){
buc[a[r]]--;
if(buc[a[r]]==1)ret--;
if(!ret){ans=min(ans,r-l+1);break;}
}
}
printf("%d\n",ans);
}
}
int main(){
// srand(19260817);
// freopen("signin.in","r",stdin);
// freopen("signin.out","w",stdout);
MAIN::MAIN();
return 0;
}
```