diff --git a/PBDS/Codeforces PBDS example.cpp b/PBDS/Codeforces PBDS example.cpp new file mode 100644 index 00000000..cb1f85a1 --- /dev/null +++ b/PBDS/Codeforces PBDS example.cpp @@ -0,0 +1,76 @@ +/* + PROBLEM STATEMENT: + +You are given an array a of n integers. Find the number of pairs (i,j) (1≤i +using namespace __gnu_pbds; + +*/ + +#include +using namespace std; + +//common file for PBDS(Policy based data structure, here we use orderedset) +#include +// including tree_order_statistics_node_update +#include +//namespace +using namespace __gnu_pbds; +#define int long long + +//macro definition +#define ordered_set tree, null_type, less>, rb_tree_tag, tree_order_statistics_node_update> + +#define ld long double +#define endl "\n" +const int mod=1000000007; +const int MAX=100005; +mt19937_64 rng(std::chrono::steady_clock::now().time_since_epoch().count()); + +const int bit=31; + +signed main(){ + int t=1; + cin>>t; + while(t--){ + int n,l,r; + cin>>n>>l>>r; + + int arr[n]; + for(int i=0;i>arr[i]; + + ordered_set st; + + int ans=0; + int tim=0; + + for(int i=n-1;i>=0;i--){ + //number of elements strictly less than l-arr[i] + int lo=st.order_of_key({l-arr[i],-1}); + + //number of elements strictly less than r-arr[i] + int hi=st.order_of_key({r-arr[i],INT_MAX}); + st.insert({arr[i],tim++}); + ans+=(hi-lo); + } + cout<