Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <map>
- #include <vector>
- using namespace std;
- int v[10000001];
- int main() {
- int ncases,ncorn,c;
- cin>>ncases;
- while(ncases--){
- map<int,int>m;
- map<int,int>ubi;
- cin>>ncorn;
- int max=0,k=0;
- for(int i=1;i<=ncorn;i++){
- cin>>c;
- //cout<<"Lee "<<c<<endl;
- v[i]=c;
- if (m[c]==0){
- k++;
- //cout<<"k es "<<k<<endl;
- m[c]=1;
- }
- else{
- for(int j=(i-k);j<=ubi[c];j++){
- //cout<<"m["<<v[j]<<"] ahora es cero"<<endl;
- m[v[j]]=0;}
- k=i-ubi[c];
- //cout<<"Repetido, k es "<<k<<endl;
- m[c]=1;
- }
- if (k>max){
- max=k;
- //cout<<"Max ahora es "<<max<<endl;
- }
- ubi[c]=i;
- }
- cout<<max<<endl;
- m.clear();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment