Here you will find solutions of many problems on spoj. If you want solution of some problem which is not listed in blog or have doubt regarding any spoj problem (which i have solved) or any programming concept (data structure) you can mail me @
And my humble request to you all that don't copy the code only try to understand the logic and algorithm behind the code. I have started this because if you tried as hard as you can and still can't find any solution to the problem then you can refer to this.
You can read my answer how to start competitive programming CLICK HERE

Wednesday, October 15, 2014

YODANESS-Yodaness Level

Yodaness Level

Given Below code is for yodaness spoj or yodaness level spoj.

Hint :-> Its just simple problem on BIT for counting inversion count . (read bit from top coder)

#include <bits/stdc++.h>
using namespace std;
#define LL long long
void update(LL arr[],int pos,int val,int MAX)
        arr[pos] += val;
        pos += (pos & -pos);
LL read(LL arr[],int pos)
    LL sum = 0;
        sum += arr[pos];
        pos -= (pos & -pos);
    return sum;
int main()
    int t;
        int n;
        string s[n+9],temp;
        for(int i = 0;i < n;i++)
        int count = 1;
        map<string,int> mp;
            mp[temp] = count;
        int arr[n+9];
        count = 0;
        for(int i = 0;i<n;i++)
            arr[i] = mp[s[i]];
        LL tree[n+9];
        memset(tree,0,sizeof tree);
        LL total = 0;
        for(int i = n - 1 ; i >= 0 ; i--)
            total += read(tree,arr[i]);
        printf("%lld\n", total);
    return 0;