Matrix_code

data-strucure - Policy Based Data Structure(OS)

May 5th, 2016 (edited)
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.23 KB | None | 0 0
  1. /************************************************************************************************
  2.      The order-statistics tree supports the same operations as the set
  3.     * find_by_order(k) : iterator to the kth smallest integer counting from 0
  4.     * order_of_key(item):  number of items in a set that are strictly smaller than our item
  5.  
  6. **********************************************************************************************/
  7. #include <ext/pb_ds/assoc_container.hpp> // Common file
  8. #include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
  9. using namespace __gnu_pbds;
  10. typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>OS;
  11. #include<bits/stdc++.h>
  12. using namespace std;
  13.  
  14. int main()
  15. {
  16.     OS X;
  17.     X.insert(1);
  18.     X.insert(2);
  19.     X.insert(4);
  20.     X.insert(8);
  21.     X.insert(16);
  22.  
  23.     cout<<*X.find_by_order(1)<<endl; // 2
  24.     cout<<*X.find_by_order(2)<<endl; // 4
  25.     cout<<*X.find_by_order(4)<<endl; // 16
  26.     cout<<(end(X)==X.find_by_order(6))<<endl; // true
  27.  
  28.     cout<<X.order_of_key(-5)<<endl;  // 0
  29.     cout<<X.order_of_key(1)<<endl;   // 0
  30.     cout<<X.order_of_key(3)<<endl;   // 2
  31.     cout<<X.order_of_key(4)<<endl;   // 2
  32.     cout<<X.order_of_key(400)<<endl; // 5
  33. }
Add Comment
Please, Sign In to add comment