Hi there! This is Rishabh Singhal’s personal blog.
Lunchtime with Fenwick Tree
ABSNX - Absolute Min Max Got the idea while solving, but the core technique used was to find - “Number of elements greater than some number $k$ in a given range $[l,r]$”. For this, merge-sort tree can be used getting $[l,r]$ range in sorted order and doing binary search $O(n\log^2{}n)$ which apparently won’t pass Time Limit. Hence another (new) idea was to use Fenwick Tree (with offline queries) with $O(n\log{}n)$ complexity.…
Read more ⟶Policy Based Data Structures and more
61E-Enemy is weak Instead of BIT + Co-ordinate Compression, policy based data structure can be used to find number of inversions (of order 3).
My approach: to form $dp[2][n]$ where $dp[1][i]$ represents number of inversions including $i^{th}$ element, of order 2, and $dp[2][i]$ is further constructed from $dp[1][i]$ for order 3. This can be done using BIT + Co-ordinate Compression
Alternate Solution: Find for every element $A[i]$, $L[i]$ i.e. number of elements left to it and less than $A[i]$ and $R[i]$ (right), and $Answer = \sum_{i=1}^n L[i]\cdot R[i]$.…
Read more ⟶Dynamic Programming - Longest Palindromic Subsequence
466C-Number Of Ways Instead of binary search, a suffix sum array of count can be created for quering for each $l[i]$. Reducing complexity from $O(n\log{}n)$ to $O(n)$.
1114D-Flood Fill One interesting idea to note was, the answer can be calculated using longest palindromic subsequence. Which inturn can be calculated by find LCS between array and it’s reverse.
Proof Link to Submission …
Read more ⟶