Can Someone Figure out Where i am Going Wrong , My Inversion Counting Scheme Works and it has Worked in SPOJ as Well , But Here it is WA
http://www.codechef.com/viewsolution/5647093
#include <iostream>
#include <vector>
#include <algorithm>
/********************************
COUNTING INVERSIONS WITH BINARY INDEXED TREES
O(n log n)
********************************/
typedef long long int ll;
using namespace std;
void update(ll n, ll val, vector<ll> &b);
ll read(ll n,vector<ll> &b);
void map(vector<ll> &a,vector<ll> &b,ll n)
{
ll temp;
a.clear();
b.clear();
for(ll i=0; i<n; i++)
{
cin>>temp;
a.push_back(temp);
b.push_back(temp);
}
sort(b.begin(),b.end());
for(ll i=0; i<n; i++)
*(a.begin()+i) = (lower_bound(b.begin(),b.end(),a[i])-b.begin())+1;
b.assign(n,0);
}
int main()
{
ios_base::sync_with_stdio(false);
ll n,m;
cin>>n>>m;
vector<ll> ori(1),bin(1);
map(ori,bin,n);
for(ll z=0; z<m; z++)
{
bin.assign(n+1,0);
ll s,e;
cin>>s>>e;
s=s-1;
e=e-1;
ori[s]= ori[s]+ori[e];
ori[e]=ori[s]-ori[e];
ori[s]=ori[s]-ori[e];
ll x,inv=0;
for(ll i=n-1; i>=0; i--)
{
x = read(ori[i]-1,bin);
inv+=x;
update(ori[i],1,bin);
}
cout<<inv%2;
}
return 0;
}
ll read(ll n,vector<ll> &b)
{
ll sum=0;
for(; n; sum+=b[n],n-=n&-n);
return sum;
}
void update(ll n, ll val, vector<ll> &b)
{
for(; n<=b.size(); b[n]+=val,n+=n&-n);
}