forked from anshuman8800/Interivew-Questions
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSort_by_Rev.cpp
More file actions
71 lines (65 loc) · 1.48 KB
/
Sort_by_Rev.cpp
File metadata and controls
71 lines (65 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*https://codeforces.com/contest/451/problem/B*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll M = 1e9 + 7;
#define REP(i, a, b) for (int i = a; i <= b; i++)
#define endl "\n"
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t = 1;
// cin >> t;
while (t--)
{
int n;
cin >> n;
vector<ll> v(n);
REP(i, 0, n - 1)
cin >> v[i];
if (n == 1)
cout << "yes\n1 1";
else
{
int f1 = 0, f2 = 0;
vector<ll> v1 = v;
sort(v1.begin(), v1.end());
for (int i = 0; i < n; i++)
{
if (v[i] != v1[i])
{
f1 = i;
break;
}
}
for (int i = n - 1; i >= 0; i--)
{
if (v[i] != v1[i])
{
f2 = i;
break;
}
}
reverse(v.begin() + f1, v.begin() + f2 + 1);
int flag = 0;
REP(i, 0, n - 1)
{
if (v[i] != v1[i])
{
flag = -1;
break;
}
}
if (flag == -1)
cout << "no" << endl;
else
{
cout << "yes" << endl;
cout << f1 + 1 << " " << f2 + 1 << endl;
}
}
}
return 0;
}