Posts

Showing posts from May, 2016

SPOJ: COT2 (MO'S ALGO)

SPOJ: COT2 (MO ' S ALGO) ///==================================================/// /// HELLO WORLD !! /// /// IT ' S ME // / // / BISHAL GAUTAM /// // / [ bsal.gautam16@gmail.com ] /// // /==================================================/// #include<bits/stdc++.h> # define X first # define Y second # define mpp make_pair # define nl printf("\n") # define SZ ( x ) (int)(x.size()) # define pb ( x ) push_back(x) # define pii pair<int,int> # define pll pair<ll,ll> // /--------------------- # define S ( a ) scanf("%d",&a) # define P ( a ) printf("%d",a) # define SL ( a ) scanf("%lld",&a) # define S2 ( a , b ) scanf("%d%d",&a,&b) # define SL2 ( a , b ) scanf("%lld%lld",&a,&b) // /------------------------------------ # define al

HackerEarth: Shil and Palindrome Research ( BIT on XOR )

HackerEarth: Shil and Palindrome Research ( BIT on XOR ) // /==================================================/// // / HELLO WORLD !! /// // / IT'S ME /// // / BISHAL GAUTAM /// // / [ bsal.gautam16@gmail.com ] /// // /==================================================/// #include<bits/stdc++.h> # define X first # define Y second # define mpp make_pair # define nl printf("\n") # define SZ ( x ) (int)(x.size()) # define pb ( x ) push_back(x) # define pii pair<int,int> # define pll pair<ll,ll> // /--------------------- # define S ( a ) scanf("%d",&a) # define P ( a ) printf("%d",a) # define SL ( a ) scanf("%lld",&a) # define S2 ( a , b ) scanf("%d%d",&a,&b) # define SL2 ( a , b ) scanf("%lld%lld",&a,&b) // /------------------

HackerEarth: Little Deepu and Array (Segment tree)

HackerEarth: Little Deepu and Array (Segment tree) ///==================================================/// /// HELLO WORLD !! /// /// IT'S ME /// /// BISHAL GAUTAM /// /// [ bsal.gautam16@gmail.com ] /// ///==================================================/// #include<bits/stdc++.h> # define X first # define Y second # define mpp make_pair # define nl printf("\n") # define SZ ( x ) (int)(x.size()) # define pb ( x ) push_back(x) # define pii pair<int,int> # define pll pair<ll,ll> ///--------------------- # define S ( a ) scanf("%d",&a) # define P ( a ) printf("%d",a) # define SL ( a ) scanf("%lld",&a) # define S2 ( a,b ) scanf("%d%d",&a,&b) # define SL2 ( a,b ) scanf("%lld%lld",&a,&b) ///------------------------------------ # defin

HackerEarth: City and Campers 2 (DSU-UnionFind)

HackerEarth: City and Campers 2 (DSU-UnionFind) ///==================================================/// /// HELLO WORLD !! /// /// IT'S ME /// /// BISHAL GAUTAM /// /// [ bsal.gautam16@gmail.com ] /// ///==================================================/// #include<bits/stdc++.h> # define X first # define Y second # define mpp make_pair # define nl printf("\n") # define SZ ( x ) (int)(x.size()) # define pb ( x ) push_back(x) # define pii pair<int,int> # define pll pair<ll,ll> ///--------------------- # define S ( a ) scanf("%d",&a) # define P ( a ) printf("%d",a) # define SL ( a ) scanf("%lld",&a) # define S2 ( a,b ) scanf("%d%d",&a,&b) # define SL2 ( a,b ) scanf("%lld%lld",&a,&b) ///------------------------------------ # define

LOJ: 1293 - Document Analyzer (Persistance SegmentTree)

LOJ: 1293 - Document Analyzer ///==================================================/// /// HELLO WORLD !! /// /// IT'S ME /// /// BISHAL GAUTAM /// /// [ bsal.gautam16@gmail.com ] /// ///==================================================/// #include<bits/stdc++.h> # define X first # define Y second # define mpp make_pair # define nl printf("\n") # define SZ ( x ) (int)(x.size()) # define pb ( x ) push_back(x) # define pii pair<int,int> # define pll pair<ll,ll> ///--------------------- # define S ( a ) scanf("%d",&a) # define P ( a ) printf("%d",a) # define SL ( a ) scanf("%lld",&a) # define S2 ( a,b ) scanf("%d%d",&a,&b) # define SL2 ( a,b ) scanf("%lld%lld",&a,&b) ///------------------------------------ # define all ( v ) v.begin()

SPOJ: BGSHOOT ( SegmentTree-DS)

SPOJ: BGSHOOT ( Segment Tree-DS ) ///==================================================/// /// HELLO WORLD !! /// /// IT'S ME /// /// BISHAL GAUTAM /// /// [ bsal.gautam16@gmail.com ] /// ///==================================================/// #include<bits/stdc++.h> # define X first # define Y second # define mpp make_pair # define nl printf("\n") # define SZ ( x ) (int)(x.size()) # define pb ( x ) push_back(x) # define pii pair<int,int> # define pll pair<ll,ll> ///--------------------- # define S ( a ) scanf("%d",&a) # define P ( a ) printf("%d",a) # define SL ( a ) scanf("%lld",&a) # define S2 ( a,b ) scanf("%d%d",&a,&b) # define SL2 ( a,b ) scanf("%lld%lld",&a,&b) ///------------------------------------ # define all ( v ) v.begi

HackerEarth: Super Power Of 2s (Segment Tree-Lazy-DS)

HackerEarth: Super Power Of 2s ///==================================================/// /// HELLO WORLD !! /// /// IT'S ME /// /// BISHAL GAUTAM /// /// [ bsal.gautam16@gmail.com ] /// ///==================================================/// #include<bits/stdc++.h> # define X first # define Y second # define mpp make_pair # define nl printf("\n") # define SZ ( x ) (int)(x.size()) # define pb ( x ) push_back(x) # define pii pair<int,int> # define pll pair<ll,ll> ///--------------------- # define S ( a ) scanf("%d",&a) # define P ( a ) printf("%d",a) # define SL ( a ) scanf("%lld",&a) # define S2 ( a,b ) scanf("%d%d",&a,&b) # define SL2 ( a,b ) scanf("%lld%lld",&a,&b) ///------------------------------------ # define all ( v ) v.begin()

HackerEarth: Kinako Bread (DS- Greedy, 2 pointers )

HackerEarth: Kinako Bread (DS- Greedy, 2 pointers ) ///==================================================/// /// HELLO WORLD !! /// /// IT'S ME /// /// BISHAL GAUTAM /// /// [ bsal.gautam16@gmail.com ] /// ///==================================================/// #include<bits/stdc++.h> # define X first # define Y second # define mpp make_pair # define nl printf("\n") # define SZ ( x ) (int)(x.size()) # define pb ( x ) push_back(x) # define pii pair<int,int> # define pll pair<ll,ll> ///--------------------- # define S ( a ) scanf("%d",&a) # define P ( a ) printf("%d",a) # define SL ( a ) scanf("%lld",&a) # define S2 ( a,b ) scanf("%d%d",&a,&b) # define SL2 ( a,b ) scanf("%lld%lld",&a,&b) ///------------------------------------ # defin

HackerEarth: Comrades - III ( DS-LazyPropagation )

HackerEarth: Comrades - III ( DS-LazyProp ) ///==================================================/// /// HELLO WORLD !! /// /// IT'S ME /// /// BISHAL GAUTAM /// /// [ bsal.gautam16@gmail.com ] /// ///==================================================/// #include<bits/stdc++.h> # define X first # define Y second # define mpp make_pair # define nl printf("\n") # define SZ ( x ) (int)(x.size()) # define pb ( x ) push_back(x) # define pii pair<int,int> # define pll pair<ll,ll> ///--------------------- # define S ( a ) scanf("%d",&a) # define P ( a ) printf("%d",a) # define SL ( a ) scanf("%lld",&a) # define S2 ( a,b ) scanf("%d%d",&a,&b) # define SL2 ( a,b ) scanf("%lld%lld",&a,&b) ///------------------------------------ # define all (

HackerEarth: Xor in Sequence (TRIE)

HackerEarth: Xor in Sequence (TRIE) ///==================================================/// /// HELLO WORLD !! /// /// IT'S ME /// /// BISHAL GAUTAM /// /// [ bsal.gautam16@gmail.com ] /// ///==================================================/// #include<bits/stdc++.h> # define X first # define Y second # define mpp make_pair # define nl printf("\n") # define SZ ( x ) (int)(x.size()) # define pb ( x ) push_back(x) # define pii pair<int,int> # define pll pair<ll,ll> ///--------------------- # define S ( a ) scanf("%d",&a) # define P ( a ) printf("%d",a) # define SL ( a ) scanf("%lld",&a) # define S2 ( a,b ) scanf("%d%d",&a,&b) # define SL2 ( a,b ) scanf("%lld%lld",&a,&b) ///------------------------------------ # define all ( v ) v.b

HackerEarth: Chemical Reaction (DS)

HackerEarth: Chemical Reaction (DS) Idea: This questions asks for implementing basic idea of finding kth odrer  and deleting that element and again doing same subsequently for large quries. This can be done easily  1.) using BIT , where prefix sum is kept by initializing all index to 1. After that cummulative sum is stored on BIT. so, for finding kth value , we need to do Binary search on index, after getting desired index,that value is made zero by updating -1 value, as +1 value was stored before. This solution takes execution time: 2.182175 2.) or we also may use segment tree keeping  prefix sum and quering for kth sum in segment tree node [ this solution  executes in time: 1.9685 Here, The first solution has been commenting out. ///==================================================/// /// HELLO WORLD !! /// /// IT'S ME /// /// BISHAL GAUTAM /// /// [ bsal.gautam