Advertisement
Guest User

Untitled

a guest
Jul 16th, 2019
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. int N,a,b,c,d,wynik;
  5. vector <pair <int, int > >tab;
  6. int main()
  7. {
  8. ios_base::sync_with_stdio(0);
  9. cin.tie(0);
  10. cin>>N;
  11. tab.push_back(make_pair(0,0));
  12. cin>>a;
  13. tab.push_back(make_pair(a,0));
  14. tab.push_back(make_pair(1000001,0));
  15. for(int i=1;i<N;i++)
  16. {
  17. cin>>a;
  18. b=0;
  19. d=tab.size();
  20. while (b < d) {
  21. c = (d + b) / 2;
  22. if (tab[c].first >= a) {
  23. d = c;
  24. }
  25. else {
  26. b = c+1;
  27. }
  28. }
  29. tab.insert(tab.begin()+c,make_pair(a,max(tab[c].second,tab[c].second)+1));
  30. wynik=max(wynik,tab[c+1].second);
  31. }
  32. for(int i=0;i<tab.size();i++)
  33. {
  34. cout<<tab[i].first<<" ";
  35. }
  36. cout<<endl;
  37. for(int i=0;i<tab.size();i++)
  38. {
  39. cout<<tab[i].second<<" ";
  40. }
  41. cout<<endl;
  42. cout<<wynik;
  43. return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement