Advertisement
fahad005

Untitled

Oct 4th, 2021
1,390
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.92 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. //
  4. #define ll long long
  5. #define ull unsigned long long
  6. #define mx 100010
  7. #define mod 1000000007
  8. #define inf INT_MAX
  9. #define pi acos(-1)
  10. #define endl '\n'
  11. #define pb push_back
  12. #define pll pair<ll, ll>
  13. #define Fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
  14. //
  15. int main() {
  16.     ll t;
  17.     cin >> t;
  18.  
  19.     while (t--) {
  20.         ll n;
  21.         cin >> n;
  22.  
  23.         ll ar[n];
  24.         for (ll i = 0; i < n; i++) cin >> ar[i];
  25.  
  26.         bool ok = true;
  27.         ll count = 0;
  28.         for (ll i = 1; i < n; i++) {
  29.             if (ar[i] < ar[i - 1]) {
  30.                 count++;
  31.                 if (ar[0] < ar[n - 1]) {
  32.                     ok = false;
  33.                     break;
  34.                 }
  35.                 if (count > 1) break;
  36.             }
  37.         }
  38.  
  39.         if (!ok || count > 1) cout << "NO" << endl;
  40.         else cout << "YES" << endl;
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement