Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma comment(linker,"/STACK:128777216")
- #include <bits/stdc++.h>
- using namespace std;
- //#define int long long
- #define all(h) h.begin(),h.end()
- //cout << (char*)&(const int&)(23438671621410638LL >> (ok << 5)) << '\n';
- struct edge{
- int n;
- edge *l= nullptr;
- edge *r= nullptr;
- };
- void build (edge *a, int b){
- if (b>a->n){
- if (a->r== nullptr){
- a->r=new edge;
- a->r->n=b;
- }
- else{
- build(a->r,b);
- }
- }
- else{
- if(a->l== nullptr){
- a->l=new edge;
- a->l->n=b;
- }
- else{
- build(a->l,b);
- }
- }
- }
- void tobeprinted (edge* a){
- if (a->r!= nullptr)tobeprinted(a->r);
- if (a->l!= nullptr)tobeprinted(a->l);
- cout << a->n << '\n';
- }
- signed main (){
- //freopen("input.txt", "r", stdin);
- //freopen("output.txt", "w", stdout);
- ios_base::sync_with_stdio(false);
- cin.tie(nullptr); cout.tie(nullptr);
- int n; cin >> n;
- vector<int> q(n);
- for (int i=0; i<n; ++i){
- cin >> q[i];
- }
- edge boss;
- boss.n=q[n-1];
- boss.l=nullptr;
- boss.r=nullptr;
- for (int i=n-2; i>-1; --i){
- build(&boss,q[i]);
- }
- tobeprinted(&boss);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement