Advertisement
Rishav_hitk_cse

Running median

Mar 29th, 2021
717
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.46 KB | None | 0 0
  1. #include <ext/pb_ds/assoc_container.hpp>
  2. #include <ext/pb_ds/tree_policy.hpp>
  3.  
  4. using namespace __gnu_pbds;
  5. using namespace std;
  6.  
  7.  
  8. typedef tree<int, null_type,greater_equal<int>, rb_tree_tag,tree_order_statistics_node_update> ordered_set;
  9.  
  10. vector<int> Solution::solve(vector<int> &a) {
  11.     vector<int> ans;
  12.     ordered_set st;
  13.     for(int x:a){
  14.         st.insert(x);
  15.         ans.push_back(*st.find_by_order(st.size()/2));
  16.     }
  17.     return ans;
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement