Computing the distribution of a Jonckheere-Terpstra statistic
I didn't read in it's entirity, but change this line

static int mannwhit(std::vector&lt;int&gt; c, std::vector&lt;int&gt; sizes)


to

static int mannwhit(const std::vector&lt;int&gt;&amp; c, 
                    const std::vector&lt;int&gt;&amp; sizes)


This won't speed up your code but you should use

#include &lt;cstdio&gt; //instead of stdio.h


and memset will need to be prefixed as std::memset.

Also ensure you compiler is compiling at 02 and with out debug flags.