Posts

CODECHEF: Funny gnomes ( Sparse Table , BitSet )

CODECHEF: Funny gnomes ( Sparse Table + Kth LCA LOGIC ) // /==================================================/// // / 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) // /--------------------...

UVA-13092-Fold the String ( Manacer+DP )

Prob : UVA -13092 - Fold the String ( Manacer + DP ) IDEA : According to problem, we have given a string ,starting from last position of string ,we have to fold the string into even palindrome mirror with cost of " Y " or we may erase last char with cost of " X " . First , Observation to solve this problem is that , from each point we should try to fold a string with maximum length possible. So, Using manacer, we find from each position , minimum possible index to which it can be folded. For this, Initially, put a minimum index to each end index of palindrome centered at some position. Then , update this minimum values to each valid index coming from backside of string . Now, finally a simple DP with two options whether to erase last char or to go to min index . / / / = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = / / / / / / HELLO WORLD !! ...

CF: Edu Round-15 (702E) [ SparseTable Logic ]

CF: Edu Round- 15 (702E) [ SparseTable Logic ] ///==================================================/// /// 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 piii pair< int ,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) ///--------...

MO's on Tree- So Close Yet So Far(Codechef)

CODECHEF:So Close Yet So Far(MO's on 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 piii pair< int ,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) ///---------...

HackerRank: Quadrant Queries ( Segment Tree )

HackerRank: Quadrant Queries ( 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) // /------------------------------...

HackerRank: Kingdom Connectivity (Tarjan SCC+DP)

HackerRank: Kingdom Connectivity (Tarjan+DP) // /==================================================/// // / 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) // /-------------------------------...

LOJ: 1150-Ghosts ( Bipartite Matching+BS )

LOJ: 1150 -Ghosts ( Bipartite Matching+BS ) // /==================================================/// // / 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) // /----------------------------------...