Advertisement
Guest User

Untitled

a guest
Oct 17th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. #include<iostream>
  2.  
  3. using namespace std;
  4.  
  5. int sz = 1, a[1000001];
  6. pair<int, int> kol[1000001], ar[1000001];
  7.  
  8. int fun(int x, int ind)
  9. {
  10. int y = 0;
  11. if(a[ind] <= x)
  12. {
  13. if(ar[ind].second == 0)
  14. {
  15. ar[ind].second = sz;
  16. a[sz] = x;
  17. sz++;
  18. }else
  19. {
  20. y = fun(x, ar[ind].second);
  21. }
  22. return y + kol[ind].first + 1;
  23. }else
  24. {
  25. kol[ind].first++;
  26. if(ar[ind].first == 0)
  27. {
  28. ar[ind].first = sz;
  29. a[sz] = x;
  30. sz++;
  31. return 0;
  32. }else
  33. {
  34. y = fun(x, ar[ind].first);
  35. }
  36. return y;
  37. }
  38. }
  39.  
  40. int main()
  41. {
  42. int n;
  43. cin >> n;
  44. for(int i = 1; i <= n; i++)
  45. {
  46. int x;
  47. cin >> x;
  48. cout << fun(x, 0) << endl;
  49. }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement