Greedy Shopping (Codeforces)

题目

You are given an array a1,a2,…,ana1,a2,…,an of integers. This array is non-increasing.

Let's consider a line with nn shops. The shops are numbered with integers from 11 to nn from left to right. The cost of a meal in the ii-th shop is equal to aiai.

You should process qq queries of two types:

  • 1 x y: for each shop 1≤i≤x1≤i≤x set ai=max(ai,y)ai=max(ai,y).
  • 2 x y: let's consider a hungry man with yy money. He visits the shops from xx-th shop to nn-th and if he can buy a meal in the current shop he buys one item of it. Find how many meals he will purchase. The man can buy a meal in the shop ii if he has at least aiai money, and after it his money decreases by aiai.

Input

The first line contains two integers nn, qq (1≤n,q≤2⋅1051≤n,q≤2⋅105).

The second line contains nn integers a1,a2,…,ana1,a2,…,an (1≤ai≤109)(1≤ai≤109) — the costs of the meals. It is guaranteed, that a1≥a2≥…≥ana1≥a2≥…≥an.

Each of the next qq lines contains three integers tt, xx, yy (1≤t≤21≤t≤2, 1≤x≤n1≤x≤n, 1≤y≤1091≤y≤109), each describing the next query.

It i

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值