Saleh127

CF 1372C

Sep 12th, 2020
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define test int t; cin>>t; for(int cs=1;cs<=t;cs++)
  5. int main()
  6. {
  7. ios_base::sync_with_stdio(0);
  8. cin.tie(0);
  9. cout.tie(0);
  10.  
  11. test
  12. {
  13. ll a[200005],c,d,e,f,i,j=0,k,l=0;
  14. cin>>c;
  15. for(i=1; i<=c; i++)
  16. {
  17. cin>>a[i];
  18. if(a[i]==i)
  19. {
  20. j++;
  21. }
  22. }
  23. if(j==c)
  24. {
  25. cout<<0<<endl;
  26. continue;
  27. }
  28.  
  29. for(i=1; i<=c; i++)
  30. {
  31. if(a[i]!=i)
  32. {
  33. j=i;
  34. break;
  35. }
  36. }
  37. for(i=c; i>=1; i--)
  38. {
  39. if(a[i]!=i)
  40. {
  41. k=i;
  42. break;
  43. }
  44. }
  45. for(i=j; i<=k; i++)
  46. {
  47. if(a[i]==i)
  48. {
  49. l=1;
  50. }
  51. }
  52. if(l) cout<<2<<endl;
  53. else cout<<1<<endl;
  54. }
  55. return 0;
  56. }
  57.  
Advertisement
Add Comment
Please, Sign In to add comment