Optimal preprocessing for certain types of queries
Construct an ordered balanced binary tree with $s_1,\dots,s_n$ in the leaves (in order).  In each internal node $v$ store the product of the leaves of the subtree rooted at $v$.  This preprocessing obviously runs in O$(n)$ time and space.

Now, to compute a product $s_i\circ\ldots\circ s_j$ (where $i&lt;j$) walk the tree up from $i$ to the least common ancestor (LCA) of $i$ and $j$.  Collect the products stored in each right child hanging off the path, excluding the right child of the LCA.  In other words, as you go up from $u$ to its parent $v$, if $u$ is a left child of $v$, then pick up the product stored in $v$'s right child.  Similarly, walk up from $j$ to the LCA and collect the products stored in left children hanging off that path.  Multiply all these products, along with $s_i$ and $s_j$ in order.