CF1439C.Greedy Shopping

省选/NOI-

通过率:0%

时间限制:3.00s

内存限制:256MB

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 1≤i≤x1 \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.

给你一个整数数组 a1,a2,…,ana_1, a_2, \ldots, a_n,该数组是非递增的。

考虑一条直线上有 nn 家商店,商店从左到右依次编号为 11 到 nn。第 ii 家商店中一份餐食的价格为 aia_i。

你需要处理 qq 个查询,查询分为两种类型:

  • 1 x y:对每个满足 1≤i≤x1 \leq i \leq x 的商店 ii,执行 ai=max⁡(ai,y)a_{i} = \max(a_{i}, y)。
  • 2 x y:假设一位饥饿的人拥有 yy 元钱。他从第 xx 家商店开始,依次访问第 xx、x+1x+1、…、nn 家商店;若他在当前商店有足够的钱购买一份餐食,则他会购买一份。求他总共会购买多少份餐食。该人能在第 ii 家商店购买餐食,当且仅当他当前拥有的钱数不少于 aia_i;购买后,他的钱数减少 aia_i。

输入格式

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

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

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

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

第一行包含两个整数 nn、qq(1≤n,q≤2⋅1051 \leq n, q \leq 2 \cdot 10^5)。

第二行包含 nn 个整数 a1,a2,…,ana_{1},a_{2}, \ldots, a_{n}(1≤ai≤1091 \leq a_{i} \leq 10^9)—— 各餐食的成本。保证满足 a1≥a2≥…≥ana_1 \geq a_2 \geq \ldots \geq a_n。

接下来的 qq 行中,每行包含三个整数 tt、xx、yy(1≤t≤21 \leq t \leq 2,1≤x≤n1\leq x \leq n,1≤y≤1091 \leq y \leq 10^9),分别描述一个查询。

保证至少存在一个类型为 22 的查询。

输出格式

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

对于每个类型为 22 的查询,在新行中输出答案。

输入输出样例

  • 输入#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.

在第一次查询中,一个饥饿的人将在第 33 至第 1010 家商店购买餐食。

在第二次查询中,一个饥饿的人将在第 44、第 99 和第 1010 家商店购买餐食。

第三次查询后,费用数组 a1,a2,…,ana_1, a_2, \ldots, a_n 不会发生变化,仍为 10,10,10,6,6,5,5,5,3,1{10, 10, 10, 6, 6, 5, 5, 5, 3, 1}。

在第四次查询中,一个饥饿的人将在第 22、第 33、第 44、第 55、第 99 和第 1010 家商店购买餐食。

第五次查询后,费用数组 aa 将变为 10,10,10,7,6,5,5,5,3,1{10, 10, 10, 7, 6, 5, 5, 5, 3, 1}。

在第六次查询中,一个饥饿的人将在第 22 和第 44 家商店购买餐食。

输入解题思路,AI测评打分。不知道怎么写?

首页