fork download
  1. #include <iostream>
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4.  
  5. int main() {
  6. int T;
  7. scanf("%d",&T);
  8. while(T--){
  9. long long N;
  10. scanf("%lld",&N);
  11. vector<long long> H(N);
  12. for(int i=0;i<N;i++){
  13. scanf("%lld",&H[i]);
  14. }
  15. vector<long long> B(N);
  16. B=H;
  17. vector<long long>::iterator it;
  18. it=unique(B.begin(),B.end());
  19. B.resize( distance(B.begin(),it) );
  20. int count=B.size();
  21. for(int i=0;i<B.size();i++){
  22. int counti=0;
  23. for(int j=0;j<N;j++){
  24. if(B[i]==H[j]){
  25. counti++;
  26. }
  27. if(B[i]!=H[i]){
  28. if(counti>2){
  29. count++;
  30. counti=0;
  31. }
  32.  
  33. }
  34.  
  35. }
  36. }
  37. printf("%d",count);
  38. }
  39. return 0;
  40. }
Success #stdin #stdout 0s 16064KB
stdin
2
3
2 3 4
3
4 4 5
stdout
32