CF1266E Spaceship Solitaire 题解 思维

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 1n2

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值