Posts

HackerEarth: spartans-leonidas-vs-xerxes-monk ( DS )

HackerEarth: spartans-leonidas-vs-xerxes-monk IDEA: The problem is initially giving an array of size-N denoting power of soldiers. For every query you have to change the power of Xth index by -Y or +Y , Also, you may have to say longest increasing subarray withing segment [ x ,y ] efficiently. The idea is simple, we have to keep information of  1.)longest prefix increasing length, 2.)longest suffix increasing length, 3.)Maximum increasing length so far, 4.)begin element of segment 5.)end element of segment. Then update accordingly to get appropriate result.  See the code below for further understanding. ///==================================================/// /// HELLO WORLD !! /// /// IT'S ME /// /// BISHAL GAUTAM /// /// [ bsal.gautam16@gmail.com ] /// ///==================================================/// #include<bits/stdc++.h> # defin...

HACKEREARTH: 2 vs 3 (Segment Tree-DS)

HACKEREARTH: 2 vs 3 . ///==================================================/// /// 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(),v.end()...

HK: Heavy Light White Falcon ( HLD )

HK: Heavy Light White Falcon ( HLD ) ///==================================================/// /// 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....

HAKER-RANK :Lazy White Falcon (DS)

HR:Lazy White Falcon (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.begin(),v.e...

HDU-4734 : F(x) [ Digit DP ]

HDU - 4734 : F(X) [Digit DP] IDEA : Problem is asking for how many integers( x ) are there in the range 0 to B, which have F( x ) less than or equal to F(A). Simply a digit dp with state "POS" , "If we take any less digit" and "Tot sum for F(x)" . But, the main problem is that there are lot of test cases..So, to avoid clearing DP array for each testcases, we only memorize two state POS & SUM, so that we have only one state which will be not memorized in each testcases. CODE : ///==================================================/// /// 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 ...

HDU-4276 :The Ghost Blows Light (Tree DP)

HDU- 4276 :The Ghost Blows Light IDEA:  This is one of my favorite problem. Problem is giving us a weighted tree and each node  have value associated with it.Given a time -T, we have to move from 1 to n within time also maximizing the total value collected from nodes. Idea is simply a tree dp. First find a shortest path (let Sdis) from 1 to n in that tree and make weight of that path 0. Then simply do a tree dp starting from rooted tree at 1. Each time trying to maximizing the all possible value gaining by using time of (T-Sds). ///==================================================/// /// 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 p...

CF: 337D - Book of Evil (Tree DP)

CF: 337D - Book of Evil ///==================================================/// /// 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(),v.end(...