Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2020
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. #include <iostream>
  2. #include <map>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8. int cases;
  9. int n;
  10. int snowflake;
  11. int *snowflakes = new int[1000001];
  12. int current, first, result, counter;
  13.  
  14. cin >> cases;
  15. while(cases--){
  16. first = current = result = counter = 0;
  17. map<int,bool> taken;
  18.  
  19. cin >> n;
  20.  
  21. while (n--) {
  22. cin >> snowflake;
  23. snowflakes[current++] = snowflake;
  24.  
  25. if (taken.find(snowflake) != taken.end()) {
  26. if (counter > result) result = counter;
  27.  
  28. while (true) {
  29. if (snowflakes[first] == snowflake) break;
  30. taken.erase(snowflakes[first]);
  31. counter--;
  32. first++;
  33. }
  34.  
  35. first++;
  36. } else {
  37. counter++;
  38. taken[snowflake] = true;
  39. }
  40. }
  41.  
  42. if (counter > result) result = counter;
  43.  
  44. cout << result << endl;
  45. }
  46.  
  47. delete snowflakes;
  48.  
  49. return 0;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement