Advertisement
Guest User

Untitled

a guest
Apr 6th, 2020
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.28 KB | None | 0 0
  1. #pragma comment(linker,"/STACK:128777216")
  2. #include <bits/stdc++.h>
  3.  
  4. using namespace std;
  5.  
  6. //#define int long long
  7. #define all(h) h.begin(),h.end()
  8.  
  9. //cout << (char*)&(const int&)(23438671621410638LL >> (ok << 5)) << '\n';
  10.  
  11. struct edge{
  12.     int n;
  13.     edge *l= nullptr;
  14.     edge *r= nullptr;
  15. };
  16.  
  17. void build (edge *a, int b){
  18.     if (b>a->n){
  19.         if (a->r== nullptr){
  20.             a->r=new edge;
  21.             a->r->n=b;
  22.         }
  23.         else{
  24.             build(a->r,b);
  25.         }
  26.     }
  27.     else{
  28.         if(a->l== nullptr){
  29.             a->l=new edge;
  30.             a->l->n=b;
  31.         }
  32.         else{
  33.             build(a->l,b);
  34.         }
  35.     }
  36. }
  37. void tobeprinted (edge* a){
  38.     if (a->r!= nullptr)tobeprinted(a->r);
  39.     if (a->l!= nullptr)tobeprinted(a->l);
  40.     cout << a->n << '\n';
  41. }
  42.  
  43.  
  44. signed main (){
  45.     //freopen("input.txt", "r", stdin);
  46.     //freopen("output.txt", "w", stdout);
  47.     ios_base::sync_with_stdio(false);
  48.     cin.tie(nullptr); cout.tie(nullptr);
  49.     int n; cin >> n;
  50.     vector<int> q(n);
  51.     for (int i=0; i<n; ++i){
  52.         cin >> q[i];
  53.     }
  54.     edge boss;
  55.     boss.n=q[n-1];
  56.     boss.l=nullptr;
  57.     boss.r=nullptr;
  58.     for (int i=n-2; i>-1; --i){
  59.         build(&boss,q[i]);
  60.     }
  61.     tobeprinted(&boss);
  62.  
  63.  
  64.     return 0;
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement