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

Thursday, October 16, 2014

NICEDAY - The day of the competitors

The day of the competitors

Given Below c++ code is for NICEDAY spoj or the day of the competitiors spoj.

Hint :-> Binary Index Tree

#include <bits/stdc++.h>
using namespace std;
int tree[100009];
void update(int pos,int val,int MAX)
    while(pos <= MAX)
        tree[pos] = min(tree[pos] , val);
        pos += (pos & -pos);
int read(int pos)
    int check = INT_MAX;
        check = min(tree[pos] , check);
        pos -= (pos & -pos);
    return check;
struct data
    int first,second,third;
bool cmp(const data &a , const data &b)
    return a.first == b.first ? (a.second == b.second ? a.third < b.third : a.second < b.second ) : a.first < b.first;
int main()
    int t;
        int n;
        data arr[n+9];
        for(int i=0;i<n;i++)
        fill(tree,tree + n + 9 , INT_MAX);
        int res = 0;
        for(int i =0; i<n ; i++)
            int curr = read(arr[i].second);
            if(curr > arr[i].third)
    return 0;