set.find() not working for ordered multiset

38 views Asked by At

I am using a ordered mutliset, When I try to check if a element is present or not using st.find() it is not giving right output.

#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;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;  

int main()
{
    ordered_set st;
    for(int i = 1;i<=3;i++)st.insert(i);
    if(st.find(2)!=st.end())cout<<"Yes"<<endl;
    else cout<<"NO"<<endl;
}

the output of the above code is NO, which is wrong

But if I change less_equal to equal in tree definition which makes it ordered set not multiset, then st.find() method is working correctly.

basically, changing


typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;  

to


typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;  

gives "Yes" as the output but then it is not a multiset anymore.

I haven't read the docs, so I might be missing something basic.

UPDATE just found this link Creating ordered multiset with correctly working find() and may be there's no direct method to use find.

0

There are 0 answers