fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define fast_io ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
  5. #define int long long
  6. #define rep(i,a,b) for(int i=a;i<b;++i)
  7. #define yes cout << "YES\n"
  8. #define no cout << "NO\n"
  9.  
  10. void solve() {
  11. int n; cin >> n;
  12. int* a = new int[n];
  13. rep(i, 0, n) cin >> a[i];
  14.  
  15. int i = 0;
  16. while (i + 1 < n && a[i] <= a[i + 1]) ++i;
  17.  
  18. // allow all-equal case
  19. bool all_equal = true;
  20. rep(j, 1, n) {
  21. if (a[j] != a[0]) {
  22. all_equal = false;
  23. break;
  24. }
  25. }
  26.  
  27. if (!all_equal && (i == 0 || i == n - 1)) {
  28. no;
  29. delete[] a;
  30. return;
  31. }
  32.  
  33. while (i + 1 < n && a[i] >= a[i + 1]) ++i;
  34.  
  35. if (i == n - 1) yes;
  36. else no;
  37.  
  38. delete[] a;
  39. }
  40.  
  41. int32_t main() {
  42. fast_io;
  43. int t; cin >> t;
  44. while (t--) solve();
  45. return 0;
  46. }
  47.  
Success #stdin #stdout 0.01s 5320KB
stdin
4
4
5 6 1 1
3
3 1 2
3
40 60 90
2
1 1
stdout
YES
NO
NO
YES