Codeforces 165, USACO Feb2012, ACMQUALIFIER, segment tree problem