HDU4348 To The Moon <带修主席树>
Problem
【HDU4348】To The Moon
Description
To The Moon is a independent game released in November 2011, it is a role-playing adventure game powered by RPG Maker.
The premise of To The Moon is based around a technology that allows us to permanently reconstruct the memory on dying man. In this problem, we’ll give you a chance, to implement the logic behind the scene.
You‘ve been given integers . On these integers, you need to implement the following operations:
- : Adding a constant d for every , and increase the time stamp by , this is the only operation that will cause the time stamp increase.
- : Querying the current sum of .
- : Querying a history sum of in time .
- : Back to time . And once you decide return to a past, you can never be access to a forward edition anymore.
, , , . The system start from time , and the first modification is in time , , and won’t introduce you to a future state.
Input
1 | n m |
Output
1 | ... (for each query, simply print the result. ) |
Sample Input
1 | 10 5 |
Sample Output
1 | 4 |
标签:带修主席树
Translation
维护一个数据结构,使得其可有四种操作:区间修改,区间求和,某时间的区间和,返回某时间。
Solution
很明显这是一道主席树的板子题。不过此题要带区间修改。
普通区间修改需要加,并不断下传。而对于主席树,下传意味着新建节点,可能会。所以这里我们暴力一点,直接标记永久化,这样写起来简洁,而且省空间。
Code
1 |
|