Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- typedef long long ll;
- typedef vector<int> vi;
- typedef pair<int,int> pi;
- #define F first
- #define S second
- #define PB push_back
- #define MP make_pair
- const ll OO = (ll) 1e9+7;
- map<ll,ll> m;
- vector<ll> seq;
- int main()
- {
- // input 2 1 2 2 3 1 2 3 output 3
- ios_base::sync_with_stdio(false);
- cin.tie(NULL);
- cin.tie(NULL);
- freopen("smallest.in","r",stdin);
- int t,n;
- cin>>t;
- while(t--){
- m.clear();
- seq.clear();
- cin>>n;
- int ans=n;
- for(int i=0;i<n;i++){
- int tmp;
- cin>>tmp;
- m[tmp]++;
- seq.PB(tmp);
- }
- int j=n-1;
- for(int i=0;i<n;i++){
- if(i>j) break;
- m[seq[i-1]]--;
- while((j<n-1)&&(m[seq[i-1]] == 0)){
- j++;
- m[seq[j]]++;
- }
- if(m[seq[i-1]] == 0)
- break;
- while((i<j)&&(m[seq[j]] > 1)){
- if (m[seq[j]] > 1){
- m[seq[j]]--;
- j--;
- }
- else
- break;
- }
- while((i<j)&&(m[seq[i]] > 1)){
- m[seq[i]]--;
- i++;
- }
- ans = min(j-i+1,ans);
- }
- cout<<ans<<endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement