Welcome to my blog with some of my work in progress. I’ve been working on this book idea. You can read some of the chapters below. Not.

# Recent Articles

# 818 Race Car

Proof Consider overshooting \(t\) by \(2^{n}-1\), where \(n\) is the smallest integer that overshoots the target.
We would like to prove considering a jump \(2^{n+1}-1\) is not going to yield a shorter set of actions.
Note that \(t\) is in \([2^{n-1},2^n-2]\), so from point A we have a remaining distance in \([2^n+1, 3(2^n)-1]\). Again if we consider the possible jumps from A, either we jump to \(2^{n}-1\) or \(2^{n+1}-1\). Of course we will not take \(2^{n+1}-1\) because that would mean we arrive back at the beginning.

read more
# Codeforces Till-I-Collapse (Part III)

extent of region We begin with the segment tree version. Note that Ershov uses a version of the segment tree where the right side of the range of responsibility is open, i.e. \([3,4)\) is equivalent to \([3,3]\)
The function get below will find the size of the largest range whose prefix sum is \(k\).
int get(int v, int vl, int vr, int &k) { if (k >= st[v]) { k -= st[v]; return vr - vl; } if (vl == vr - 1) { return 0; } int mid = (vl + vr) / 2; int res = get(v * 2, vl, mid, k); if (res == mid - vl) { res += get(v * 2 + 1, mid, vr, k); } return res; } It does so by allowing the \(k\) to go down to \(0\), while there are empty ranges the recursion goes to the right child, until it reaches a single element range containing an element (\(>0\)) at which point it returns \(0\).

read more
# Codeforces Till-I-Collapse (Part II)

credits It is interesting that MiFaFAOvO’s solution has the same pieces are ershov.stanislav’s solution. In fact they both use the worm method (my own naming for subsequence like states). What is interesting from MiFaFAOvO’s solution is that he uses a BIT to solve the problem.
what kind of tree is a BIT While the update part of a BIT is pretty straightforward one may wonder at the reverse query part which was done in ershov’s solution \(O(\log n)\).

read more