Advertisement
stillnotred

Untitled

Apr 20th, 2024
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1.  
  2. #include <bits/stdc++.h>
  3. #include<ext/pb_ds/assoc_container.hpp>
  4. #include<ext/pb_ds/tree_policy.hpp>
  5. using namespace std;
  6. using namespace __gnu_pbds;
  7. #define ll long long
  8. #define pb push_back
  9. #define mp make_pair
  10. #define endl '\n'
  11. typedef vector<ll> vl;
  12. typedef long int int32;
  13. typedef unsigned long int uint32;
  14. typedef long long int int64;
  15. typedef unsigned long long int uint64;
  16. #define all(x) x.begin(), x.end()
  17. inline void solve(){
  18. ll n;cin >> n;
  19. vl v(n);
  20. rep(i,0,n){
  21. cin >> v[i];
  22. }
  23. ll trash;cin >> trash;
  24. stack<int> st;
  25. for(int i = 0;i < n;i++){
  26. while(!st.empty() && (st.top() > v[i])){
  27. st.pop();
  28. }
  29. st.push(v[i]);
  30. }
  31. vl pos(1005);
  32. vl ans;
  33. while(!st.empty()){
  34. ans.pb(st.top());
  35. pos[st.top()] = 1;
  36. st.pop();
  37. }
  38. reverse(all(ans));
  39. for(ll i = n - 1;i >= 0;i--){
  40. if(pos[v[i]] == 1){
  41. continue;
  42. }
  43. else ans.pb(v[i]);
  44. }
  45. cout << ((is_sorted(all(ans)) ? "yes" : "no"));
  46. }
  47. int main(){
  48. ios_base::sync_with_stdio(0);
  49. cin.tie(0);
  50. cout.tie(0);
  51. int t = 1;
  52. // cin >> t
  53. while (t--){
  54. solve();
  55. cout<<endl;
  56. }
  57. return 0;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement