fork download
  1. #include <bits/stdc++.h>
  2. #include <ext/pb_ds/assoc_container.hpp>
  3. #include <ext/pb_ds/tree_policy.hpp>
  4.  
  5. using namespace std;
  6. using namespace __gnu_pbds;
  7. using ll = long long;
  8. using ld = long double;
  9.  
  10. #define all(x) x.begin(),x.end()
  11. #define v(x) vector<x>
  12. #define nl '\n'
  13. #define fxd(x) fixed << setprecision(x)
  14. template<class t> using ordered_set = tree<t, null_type, less<t>, rb_tree_tag, tree_order_statistics_node_update>;
  15. template<class t> using ordered_multiset = tree<t, null_type, less_equal<t>, rb_tree_tag, tree_order_statistics_node_update>;
  16.  
  17.  
  18. bool issorted(vector<ll>& arr)
  19. {
  20. bool good = true;
  21. for (int i = 0; i < arr.size()-1; i++)
  22. {
  23. if(arr[i] > arr[i+1])
  24. {
  25. good = false;
  26. break;
  27. }
  28. }
  29. return good;
  30. }
  31.  
  32. int main()
  33. {
  34. ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
  35. int n; cin >> n;
  36. v(ll) arr(n);
  37. for (int i = 0; i < n; i++)
  38. {
  39. cin >> arr[i];
  40. }
  41. if(issorted(arr))
  42. {
  43. cout << "yes"<< nl << 1 << " " << 1;
  44. return 0;
  45. }
  46. int l = -1 , r = -1;
  47. bool oneseg = true;
  48. for (int i = 1; i < n; i++)
  49. {
  50. if(arr[i] < arr[i-1])
  51. {
  52. if(oneseg)
  53. {
  54. if(l == -1)
  55. {
  56. l = i;
  57. r = i+1;
  58. }
  59. else
  60. {
  61. r = i+1;
  62. }
  63. }
  64. else
  65. {
  66. cout << "no" ;
  67. return 0;
  68. }
  69. }
  70. else
  71. {
  72. if(r != -1)
  73. {
  74. oneseg = false;
  75. }
  76. }
  77. }
  78. //cout << l << " " << r;
  79. reverse(arr.begin()+l-1 , arr.begin()+r);
  80.  
  81. if(issorted(arr))
  82. {
  83. cout << "yes"<< nl << l << " " << r;
  84. }
  85. else
  86. {
  87. cout << "no";
  88. }
  89. }
Success #stdin #stdout 0s 5324KB
stdin
Standard input is empty
stdout
yes
1 1