fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. const int maxN = 1e6+5;
  4.  
  5. int n, a[maxN];
  6.  
  7. void solve()
  8. {
  9. set<int>leaf;
  10. leaf.insert(a[1]);
  11. for(int i=2; i<=n; i+=1)
  12. {
  13. auto mn = leaf.lower_bound(a[i]);
  14. if(mn == leaf.begin())
  15. {
  16. cout<<"No"<<'\n';
  17. return;
  18. }
  19. leaf.insert(a[i]);
  20. }
  21. cout<<"Yes"<<'\n';
  22. }
  23. int main() {
  24. int test = 1;
  25. cin>>test;
  26. while(test--)
  27. {
  28. cin>>n;
  29. for(int i=1; i<=n; i+=1) cin>>a[i];
  30. solve();
  31. }
  32. return 0;
  33. }
Success #stdin #stdout 0.01s 5300KB
stdin
9
6
1 3 4 5 2 6
4
3 4 1 2
5
4 3 5 1 2
4
1 2 3 4
7
4 3 5 7 6 2 1
6
2 4 6 1 3 5
3
2 1 3
4
2 4 1 3
6
4 2 6 5 1 3
stdout
Yes
No
No
Yes
No
No
No
No
No