首页 > 其他 > 详细

ordered_set

时间:2020-03-28 21:34:49      阅读:74      评论:0      收藏:0      [点我收藏+]

ordered_set

可以在set中找到小于某个数的元素的个数

useful

#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

int main(){
	ordered_set<int>  s;
	s.insert(1);
    s.insert(2);
    s.insert(3);
    s.insert(4);
    cout << s.order_of_key(1) << endl; // the number of elements in the s less than 1
    cout << s.order_of_key(2) << endl; // the number of elements in the s less than 2
    cout << s.order_of_key(3) << endl; // the number of elements in the s less than 3
    cout << s.order_of_key(4) << endl; // the number of elements in the s less than 4
	cout << *s.find_by_order(0) << endl; // print the 0-th smallest number in s(0-based)
    auto it = s.find_by_order(1);
    cout << *it << endl;//3
}

ordered_set

原文:https://www.cnblogs.com/guaguastandup/p/12589516.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!