fork(2) download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. struct node
  4. {
  5. long value;
  6. node *lchild;
  7. node *rchild;
  8. };
  9. node * tree=NULL;
  10. long n,q,c=1,num;
  11. node * buildtree(node *t)
  12. {
  13. if(t==NULL)
  14. {
  15. t=new node;
  16. t->value=num;
  17. t->lchild=NULL;
  18. t->rchild=NULL;
  19. return t;
  20. }
  21. else if(t->value>num)
  22. {
  23. c++;
  24. buildtree(t->lchild);
  25. }
  26. else
  27. buildtree(t->rchild);
  28. }
  29. int main()
  30. {
  31. deque<long> deq;
  32. cin>>n;
  33. c=1;
  34. for(int i=1;i<=n;i++)
  35. {
  36. cin>>num;
  37. c=1;
  38. tree=buildtree(tree);
  39. deq.push_back(c);
  40. }
  41. for(int i=0;i<deq.size();i++)
  42. cout<<deq[i]<<endl;
  43. }
Success #stdin #stdout 0s 2824KB
stdin
6
78
24
68
40
39
89
stdout
1
2
1
2
2
1