CF1439C.Greedy Shopping
省选/NOI-
通过率:0%
时间限制:3.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given an array a1,a2,…,an of integers. This array is non-increasing.
Let's consider a line with n shops. The shops are numbered with integers from 1 to n from left to right. The cost of a meal in the i-th shop is equal to ai.
You should process q queries of two types:
- 1 x y: for each shop 1≤i≤x set ai=max(ai,y).
- 2 x y: let's consider a hungry man with y money. He visits the shops from x-th shop to n-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 i if he has at least ai money, and after it his money decreases by ai.
给你一个整数数组 a1,a2,…,an,该数组是非递增的。
考虑一条直线上有 n 家商店,商店从左到右依次编号为 1 到 n。第 i 家商店中一份餐食的价格为 ai。
你需要处理 q 个查询,查询分为两种类型:
1 x y:对每个满足 1≤i≤x 的商店 i,执行 ai=max(ai,y)。2 x y:假设一位饥饿的人拥有 y 元钱。他从第 x 家商店开始,依次访问第 x、x+1、…、n 家商店;若他在当前商店有足够的钱购买一份餐食,则他会购买一份。求他总共会购买多少份餐食。该人能在第 i 家商店购买餐食,当且仅当他当前拥有的钱数不少于 ai;购买后,他的钱数减少 ai。
输入格式
The first line contains two integers n, q (1≤n,q≤2⋅105).
The second line contains n integers a1,a2,…,an (1≤ai≤109) — the costs of the meals. It is guaranteed, that a1≥a2≥…≥an.
Each of the next q lines contains three integers t, x, y (1≤t≤2, 1≤x≤n, 1≤y≤109), each describing the next query.
It is guaranteed that there exists at least one query of type 2.
第一行包含两个整数 n、q(1≤n,q≤2⋅105)。
第二行包含 n 个整数 a1,a2,…,an(1≤ai≤109)—— 各餐食的成本。保证满足 a1≥a2≥…≥an。
接下来的 q 行中,每行包含三个整数 t、x、y(1≤t≤2,1≤x≤n,1≤y≤109),分别描述一个查询。
保证至少存在一个类型为 2 的查询。
输出格式
For each query of type 2 output the answer on the new line.
对于每个类型为 2 的查询,在新行中输出答案。
输入输出样例
输入#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 3 to 10.
In the second query a hungry man will buy meals in shops 4, 9, and 10.
After the third query the array a1,a2,…,an of costs won't change and will be 10,10,10,6,6,5,5,5,3,1.
In the fourth query a hungry man will buy meals in shops 2, 3, 4, 5, 9, and 10.
After the fifth query the array a of costs will be 10,10,10,7,6,5,5,5,3,1.
In the sixth query a hungry man will buy meals in shops 2 and 4.
在第一次查询中,一个饥饿的人将在第 3 至第 10 家商店购买餐食。
在第二次查询中,一个饥饿的人将在第 4、第 9 和第 10 家商店购买餐食。
第三次查询后,费用数组 a1,a2,…,an 不会发生变化,仍为 10,10,10,6,6,5,5,5,3,1。
在第四次查询中,一个饥饿的人将在第 2、第 3、第 4、第 5、第 9 和第 10 家商店购买餐食。
第五次查询后,费用数组 a 将变为 10,10,10,7,6,5,5,5,3,1。
在第六次查询中,一个饥饿的人将在第 2 和第 4 家商店购买餐食。
输入解题思路,AI测评打分。不知道怎么写?