• Source
    1. #include<stdio.h>
    2. #include<iostream>
    3. #include<set>
    4. #define sz 1000000
    5.  
    6. using namespace std;
    7.  
    8. set<int>st;
    9.  
    10. long long arr[sz+10];
    11.  
    12. int main()
    13. {
    14. long long test,n,i,mx,ln;
    15.  
    16. scanf("%lld",&test);
    17.  
    18. while(test--)
    19. {
    20. scanf("%lld",&n);
    21.  
    22. mx=0;
    23.  
    24. for(i=1; i<=n; i++)
    25. {
    26. scanf("%lld",&arr[i]);
    27. }
    28.  
    29. ln=1;
    30.  
    31. for(i=1; i<=n; i++)
    32. {
    33. if(st.find(arr[i])==st.end())
    34. {
    35. st.insert(arr[i]);
    36. mx=max(mx,i-ln+1);
    37. }
    38.  
    39. else
    40. {
    41.  
    42. for(; arr[ln]!=arr[i]; ln++)
    43. {
    44. st.erase(arr[ln]);
    45. }
    46. ln++;
    47. mx=max(mx,i-ln+1);
    48. }
    49.  
    50. }
    51. printf("%lld\n",mx);
    52. st.clear();
    53. }
    54. return 0;
    55. }
    56.