fork download
  1. #include <bits/stdc++.h>
  2. #define ll long long int
  3. using namespace std;
  4.  
  5.  
  6. int main()
  7. {
  8.  
  9. #ifndef ONLINE_JUDGE
  10.  
  11.  
  12. freopen("input.txt","r",stdin);
  13. freopen("output.txt","w",stdout);
  14.  
  15. #endif
  16.  
  17. ll t;
  18. cin>>t;
  19. while(t--)
  20. {
  21. ll n;
  22. cin>>n;
  23. ll a[n];
  24. for (int i = 0; i < n; ++i)
  25. {
  26. cin>>a[i];
  27. }
  28.  
  29. ll child=2;
  30. ll depth=0;
  31.  
  32. bool isSorted=true;
  33. for (int i = 1; i <n;)
  34. {
  35.  
  36. for(int j=i+1;j<i+child;j++)
  37. {
  38. if(a[j]>a[j+1])
  39. {
  40. isSorted=false;
  41. break;
  42. }
  43. }
  44.  
  45.  
  46. if(isSorted)
  47. {
  48. depth++;
  49. child*=2;
  50. }
  51. else
  52. {
  53. depth+=2;
  54. child=1;
  55. isSorted=true;
  56. }
  57.  
  58. i+=child;
  59. }
  60.  
  61. cout<<depth<<endl;
  62.  
  63. //cout<<temp2<<" "<<temp1<<endl;
  64.  
  65. }
  66.  
  67.  
  68. return 0;
  69.  
  70.  
  71.  
  72. }
  73.  
Success #stdin #stdout 0s 4292KB
stdin
3
4
1 4 3 2
2
1 2
3
1 2 3
stdout
3
1
1