From cc0b9a34e390f0958d369ba329062b46ac8c66e2 Mon Sep 17 00:00:00 2001 From: kamleshranjan Date: Fri, 4 Oct 2019 17:22:43 +0530 Subject: [PATCH] Inversion count using BIT inversion count using binary indexed tree --- CppInterviewPrep/bit_inversion_count.cpp | 63 ++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 CppInterviewPrep/bit_inversion_count.cpp diff --git a/CppInterviewPrep/bit_inversion_count.cpp b/CppInterviewPrep/bit_inversion_count.cpp new file mode 100644 index 0000000..03f62d4 --- /dev/null +++ b/CppInterviewPrep/bit_inversion_count.cpp @@ -0,0 +1,63 @@ +#include +using namespace std; +int getsum(vector& BIT,int x) +{ int sum=0; + while(x>0) + { + sum+=BIT[x]; + x-=(x&(-x)); + } + return sum; +} +void update(vector& BIT,int val,int x) +{ + + while(x &A) { + int maxi=INT_MIN; + vector B,c(A.size()); + for(int i=0;iBIT(maxi+1,0); + int count=0; + for(int i=0;i A; + int n; + cin>>n; + for(int i=0;i>a; + A.push_back(a); + } + cout<