From 3a67f9171882168794c49f4fc3c64ef003475803 Mon Sep 17 00:00:00 2001 From: REETESH TOMAR <54767198+Reetesh-Tomar@users.noreply.github.com> Date: Tue, 18 Oct 2022 02:02:38 +0530 Subject: [PATCH 1/2] PBDS --- PBDS/readme.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 PBDS/readme.txt diff --git a/PBDS/readme.txt b/PBDS/readme.txt new file mode 100644 index 00000000..4c82132a --- /dev/null +++ b/PBDS/readme.txt @@ -0,0 +1 @@ +Policy based data structure From 12ade1f0da1b5d0e1d9a2efc2a0c2977179485b2 Mon Sep 17 00:00:00 2001 From: REETESH TOMAR <54767198+Reetesh-Tomar@users.noreply.github.com> Date: Tue, 18 Oct 2022 02:03:13 +0530 Subject: [PATCH 2/2] PBDS --- PBDS/Codeforces PBDS example.cpp | 76 ++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 PBDS/Codeforces PBDS example.cpp 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<