karlangadas

Unique Snowflakes

Dec 8th, 2016
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.73 KB | None | 0 0
  1. #include <iostream>
  2. #include <map>
  3. #include <vector>
  4. using namespace std;
  5. int v[10000001];
  6. int main() {
  7.     int ncases,ncorn,c;
  8.    
  9.     cin>>ncases;
  10.     while(ncases--){
  11.         map<int,int>m;
  12.         map<int,int>ubi;
  13.        
  14.         cin>>ncorn;
  15.         int max=0,k=0;
  16.         for(int i=1;i<=ncorn;i++){
  17.            
  18.             cin>>c;
  19.             //cout<<"Lee "<<c<<endl;
  20.             v[i]=c;
  21.             if (m[c]==0){
  22.                 k++;
  23.                 //cout<<"k es "<<k<<endl;
  24.                 m[c]=1;
  25.             }
  26.             else{
  27.                 for(int j=(i-k);j<=ubi[c];j++){
  28.                     //cout<<"m["<<v[j]<<"] ahora es cero"<<endl;
  29.                     m[v[j]]=0;}
  30.                 k=i-ubi[c];
  31.                 //cout<<"Repetido, k es "<<k<<endl;
  32.                 m[c]=1;
  33.             }
  34.             if (k>max){
  35.                 max=k;
  36.                 //cout<<"Max ahora es "<<max<<endl;
  37.             }
  38.             ubi[c]=i;
  39.         }
  40.         cout<<max<<endl;
  41.         m.clear();
  42.        
  43.     }
  44.     return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment