Yet Another Data Structure Problem

ZOJ - 3998