sets
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
int main()
{
indexed_set s;
s.insert(2);
s.insert(3);
s.insert(7);
s.insert(9);
/* 给下标,出数字 */
auto x = s.find_by_order(2);
cout << *x << "\n";
/* 给数字,出下标 */
cout << s.order_of_key(2) << "\n";
// 若该元素不存在,s.order_of_key(n) 返回的是传入的数字在s 里本该在的位置
cout << "Not exists:\n";
cout << s.order_of_key(6) << "\n";
cout << s.order_of_key(8);
return 0;
}
输出:
7
0
Not exists:
2
3