Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- //
- #define ll long long
- #define ull unsigned long long
- #define mx 100010
- #define mod 1000000007
- #define inf INT_MAX
- #define pi acos(-1)
- #define endl '\n'
- #define pb push_back
- #define pll pair<ll, ll>
- #define Fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
- //
- int main() {
- ll t;
- cin >> t;
- while (t--) {
- ll n;
- cin >> n;
- ll ar[n];
- for (ll i = 0; i < n; i++) cin >> ar[i];
- bool ok = true;
- ll count = 0;
- for (ll i = 1; i < n; i++) {
- if (ar[i] < ar[i - 1]) {
- count++;
- if (ar[0] < ar[n - 1]) {
- ok = false;
- break;
- }
- if (count > 1) break;
- }
- }
- if (!ok || count > 1) cout << "NO" << endl;
- else cout << "YES" << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement