CF1439C.Greedy Shopping

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given an array a1,a2,,ana_1, a_2, \ldots, a_n 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 aia_i .

You should process qq queries of two types:

  • 1 x y: for each shop 1ix1 \leq i \leq x set ai=max(ai,y)a_{i} = max(a_{i}, 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 aia_i money, and after it his money decreases by aia_i .

输入格式

The first line contains two integers nn , qq ( 1n,q21051 \leq n, q \leq 2 \cdot 10^5 ).

The second line contains nn integers a1,a2,,ana_{1},a_{2}, \ldots, a_{n} (1ai109)(1 \leq a_{i} \leq 10^9) — the costs of the meals. It is guaranteed, that a1a2ana_1 \geq a_2 \geq \ldots \geq a_n .

Each of the next qq lines contains three integers tt , xx , yy ( 1t21 \leq t \leq 2 , 1xn1\leq x \leq n , 1y1091 \leq y \leq 10^9 ), each describing the next query.

It is guaranteed that there exists at least one query of type 22 .

输出格式

For each query of type 22 output the answer on the new line.

输入输出样例

  • 输入#1

    10 6
    10 10 10 6 6 5 5 5 3 1
    2 3 50
    2 4 10
    1 3 10
    2 2 36
    1 4 7
    2 2 17

    输出#1

    8
    3
    6
    2

说明/提示

In the first query a hungry man will buy meals in all shops from 33 to 1010 .

In the second query a hungry man will buy meals in shops 44 , 99 , and 1010 .

After the third query the array a1,a2,,ana_1, a_2, \ldots, a_n of costs won't change and will be {10,10,10,6,6,5,5,5,3,1}\{10, 10, 10, 6, 6, 5, 5, 5, 3, 1\} .

In the fourth query a hungry man will buy meals in shops 22 , 33 , 44 , 55 , 99 , and 1010 .

After the fifth query the array aa of costs will be {10,10,10,7,6,5,5,5,3,1}\{10, 10, 10, 7, 6, 5, 5, 5, 3, 1\} .

In the sixth query a hungry man will buy meals in shops 22 and 44 .

首页