Given a array and given a range[l, r], determine the number of elements in the array greater than equal to l and less than equal to r
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define order_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define endl "\n\n"
using namespace __gnu_pbds;
using namespace std;
int main()
{
order_set os;
int n, x, l, r;
cout << "Enter Array Size :: ";
cin >> n;
cout << "Enter Array Element :: ";
for(int i=1; i<=n; i++)
{
cin >> x;
os.insert(x);
}
cout << "Enter left range and right range :: ";
cin >> l >> r;
cout << "\nNumber of Element between " << l << " and " << r << " in this array is :: ";
cout << os.order_of_key(r+1) - os.order_of_key(l) << "\n";
return 0;
}
Comments
Post a Comment