CF1266E Spaceship Solitaire
传送门
Bob is playing a game of Spaceship Solitaire. The goal of this game is to build a spaceship. In order to do this, he first needs to accumulate enough resources for the construction. There are n n n types of resources, numbered 1 1 1 through n n n. Bob needs at least a i a_i ai pieces of the i i i-th resource to build the spaceship. The number a i a_i ai is called the goal for resource i i i.
Each resource takes 1 1 1 turn to produce and in each turn only one resource can be produced. However, there are certain milestones that speed up production. Every milestone is a triple ( s j , t j , u j ) (s_j, t_j, u_j) (sj,tj,uj), meaning that as soon as Bob has t j t_j tj units of the resource s j s_j sj, he receives one unit of the resource u j u_j uj for free, without him needing to spend a turn. It is possible that getting this free resource allows Bob to claim reward for another milestone. This way, he can obtain a large number of resources in a single turn.
The game is constructed in such a way that there are never two milestones that have the same s j s_j sj and t j t_j tj, that is, the award for reaching t j t_j tj units of resource s j s_j sj is at most one additional resource.
A bonus is never awarded for 0 0 0 of any resource, neither for reaching the goal a i a_i ai nor for going past the goal — formally, for every milestone 0 < t j < a s j 0<t_j<a_{s_j} 0<tj<asj.
A bonus for reaching certain amount of a resource can be the resource itself, that is, s j = u j s_j = u_j sj=uj.
Initially there are no milestones. You are to process q q q updates, each of which adds, removes or modifies a milestone. After every update, output the minimum number of turns needed to finish the game, that is, to accumulate at least a i a_i ai of i i i-th resource for each i ∈ [ 1 , n ] i \in [1, n] i∈[1,n].
Input
The first line contains a single integer n n n ( 1 ≤ n ≤ 2 ⋅ 1 0 5 1 \leq n \leq 2 \cdot 10^5 1≤n≤2

最低0.47元/天 解锁文章
304

被折叠的 条评论
为什么被折叠?



