AT_abc467_g.Many Sweets Problem
省选/NOI-
通过率:0%
时间限制:3.00s
内存限制:1024MB
AC君温馨提醒
该题目为【atcoder】题库的题目,您提交的代码将被提交至atcoder进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
There is a length-N sequence of positive integers A=(A1,A2,…,AN). Process the following query Q times.
c x l r k: Update the value of Ac to x. Then, solve the following sub-problem and output the answer.
There are r−l+1 sweets. The deliciousness of the i-th sweet is Al+i−1.
You decide to eat sweets until the total deliciousness of the sweets eaten becomes k or more.
What is the minimum possible number of sweets you eat, if you optimally choose which sweets to eat? Output the answer.
If the total deliciousness cannot become k or more no matter how you choose the sweets to eat, output −1 instead.
给定一个长度为 N 的正整数序列 A=(A1,A2,…,AN)。你需要处理 Q 个查询。
c x l r k:将 Ac 的值更新为 x。然后,求解如下子问题并输出答案。
共有 r−l+1 颗糖果。第 i 颗糖果的美味值为 Al+i−1。
你决定持续吃糖果,直到所吃糖果的总美味值达到或超过 k。
若你能最优地选择要吃的糖果,则最少需要吃多少颗糖果?请输出该最小值。
若无论怎样选择糖果,总美味值都无法达到或超过 k,则输出 −1。
输入格式
The input is given from Standard Input in the following format:
N Q
A1 A2 … AN
query1
query2
⋮
queryQ
Each query queryq is given in the following format:
c x l r k
输入从标准输入中按以下格式给出:
N Q
A1 A2 … AN
query1
query2
⋮
queryQ
每个查询 queryq 的格式如下:
c x l r k
输出格式
Output Q lines. The q-th line should contain the answer to the q-th query.
输出 Q 行。第 q 行应包含第 q 个查询的答案。
输入输出样例
输入#1
7 5 8 2 4 1 7 3 6 1 1 4 7 9 5 2 1 3 8 6 4 1 5 9 6 5 3 5 1 7 9 4 6 4
输出#1
2 -1 4 1 1
输入#2
15 10 993115119 576136368 21553212 219853538 853822501 687675302 281611653 844033520 423210108 339630584 780395612 207907746 285523486 359061085 14767613 6 13801767 1 3 667406485 7 672229269 5 7 855399219 11 2367096 1 10 4016308479 6 5951398 8 8 413598120 6 196639646 5 11 2483790193 14 105322777 6 7 610670157 7 416730828 2 14 1236755516 9 838827476 5 14 4350335977 1 894919681 3 7 1132967029 6 932707551 6 15 1694677398
输出#2
1 2 6 1 4 1 2 -1 2 2
说明/提示
Sample 1 Explanation:
We explain the first query.
First, update A1 to 1. Then, A=(1,2,4,1,7,3,6). Now, solve the sub-problem.
In the sub-problem, there are four sweets, with deliciousness 1,7,3,6 in order.
To minimize the number of sweets eaten so that the total deliciousness becomes k=9 or more, it is optimal to eat the second and fourth sweets. Thus, the answer to the sub-problem is 2.
Constraints
- 1≤N≤105
- 1≤Q≤105
- 1≤Ai≤109
- 1≤c≤N
- 1≤x≤109
- 1≤l≤r≤N
- 1≤k≤1015
- All input values are integers.
样例 1 解释:
我们解释第一个查询。
首先,将 A1 更新为 1。此时,A=(1,2,4,1,7,3,6)。接下来,求解该子问题。
在该子问题中,共有四颗糖果,其美味值依次为 1,7,3,6。
为使所吃糖果的总美味值达到 k=9 或更高,且所吃糖果数量最少,最优策略是吃下第二颗和第四颗糖果。因此,该子问题的答案为 2。
约束条件
- 1≤N≤105
- 1≤Q≤105
- 1≤Ai≤109
- 1≤c≤N
- 1≤x≤109
- 1≤l≤r≤N
- 1≤k≤1015
- 所有输入值均为整数。
输入解题思路,AI测评打分。不知道怎么写?