insert and delete in order statistic tree
The exact implementation of Insert and Delete depends on the underlying binary tree structure which is used, but the idea is that you maintain the size field throughout the operation. Consider for example the following Insert procedure, which always inserts its element as a new leaf:

Insert(Tree, $x$)


If Tree is empty, set Tree to be $x$, and return.
Let $r$ be the root of Tree, and Left, Right its children.
If $x &lt; r$ then call Insert(Left, $x$), otherwise call Insert(Right, $x$).


Here is the updated algorithm, which maintains the size information:

Insert(Tree, $x$)


If Tree is empty, set Tree to be $x$ and size(Tree)=1, and return.
Increase size(Tree) by 1.
Let $r$ be the root of Tree, and Left, Right its children.
If $x &lt; r$ then call Insert(Left, $x$), otherwise call Insert(Right, $x$).


This is the basic idea. You can take it from here.