পলিসি বেইজড ডাটা স্ট্রাকচার (PBDS)
Implicit cartesian tree in GNU C++ STL.
C++ STL: Policy based data structures
Cartesian tree
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<bits/stdc++.h> | |
#include<ext/pb_ds/tree_policy.hpp> | |
#include <ext/pb_ds/assoc_container.hpp> | |
using namespace __gnu_pbds; | |
using namespace std; | |
typedef tree< | |
int, | |
null_type, | |
less<int>, | |
rb_tree_tag, | |
tree_order_statistics_node_update> | |
orderedSet; | |
int main() | |
{ | |
orderedSet os; | |
os.insert(5); | |
os.insert(2); | |
os.insert(6); | |
os.insert(4); | |
os.insert(2); | |
os.insert(7); | |
cout << *os.find_by_order(0)<<endl; // 2 | |
cout << *os.find_by_order(1)<<endl; // 4 | |
cout << *os.find_by_order(2)<<endl; // 5 | |
cout << *os.find_by_order(3)<<endl; // 6 | |
cout << *os.find_by_order(4)<<endl; // 7 | |
cout << ( end(os) == os.find_by_order(5) ) << " ---"<<endl; // true | |
cout << os.order_of_key(5) << endl; // 2 | |
cout << os.order_of_key(2) << endl; // 0 | |
cout << os.order_of_key(6) << endl; // 3 | |
cout << os.order_of_key(4) << endl; // 1 | |
cout << os.order_of_key(7) << endl; // 4 | |
} |
No comments:
Post a Comment