Codeforces Round #250 (Div. 1) D. The Child and Sequence(线段树+区间求模+区间查询)

NoSuchKey