AT_abc467_g.Many Sweets Problem

省选/NOI-

通过率:0%

时间限制:3.00s

内存限制:1024MB

AC君温馨提醒

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

题目描述

There is a length-NN sequence of positive integers A=(A1,A2,…,AN)A=(A_1,A_2,\dots,A_N). Process the following query QQ times.

  • c x l r k : Update the value of AcA_c to xx. Then, solve the following sub-problem and output the answer.

There are r−l+1r-l+1 sweets. The deliciousness of the ii-th sweet is Al+i−1A_{l+i-1}.
You decide to eat sweets until the total deliciousness of the sweets eaten becomes kk 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 kk or more no matter how you choose the sweets to eat, output −1-1 instead.

给定一个长度为 NN 的正整数序列 A=(A1,A2,…,AN)A=(A_1,A_2,\dots,A_N)。你需要处理 QQ 个查询。

  • c x l r k:将 AcA_c 的值更新为 xx。然后,求解如下子问题并输出答案。

共有 r−l+1r-l+1 颗糖果。第 ii 颗糖果的美味值为 Al+i−1A_{l+i-1}。
你决定持续吃糖果,直到所吃糖果的总美味值达到或超过 kk。
若你能最优地选择要吃的糖果,则最少需要吃多少颗糖果?请输出该最小值。
若无论怎样选择糖果,总美味值都无法达到或超过 kk,则输出 −1-1。

输入格式

The input is given from Standard Input in the following format:

NN QQ
A1A_1 A2A_2 …\dots ANA_N
query1\mathrm{query}_1
query2\mathrm{query}_2
⋮\vdots
queryQ\mathrm{query}_Q

Each query queryq\mathrm{query}_q is given in the following format:

cc xx ll rr kk

输入从标准输入中按以下格式给出:

NN QQ
A1A_1 A2A_2 …\dots ANA_N
query1\mathrm{query}_1
query2\mathrm{query}_2
⋮\vdots
queryQ\mathrm{query}_Q

每个查询 queryq\mathrm{query}_q 的格式如下:

cc xx ll rr kk

输出格式

Output QQ lines. The qq-th line should contain the answer to the qq-th query.

输出 QQ 行。第 qq 行应包含第 qq 个查询的答案。

输入输出样例

  • 输入#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 A1A_1 to 11. Then, A=(1,2,4,1,7,3,6)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,61,7,3,6 in order.
To minimize the number of sweets eaten so that the total deliciousness becomes k=9k=9 or more, it is optimal to eat the second and fourth sweets. Thus, the answer to the sub-problem is 22.

Constraints

  • 1≤N≤1051 \leq N \leq 10^5
  • 1≤Q≤1051 \leq Q \leq 10^5
  • 1≤Ai≤1091 \leq A_i \leq 10^9
  • 1≤c≤N1 \leq c \leq N
  • 1≤x≤1091 \leq x \leq 10^9
  • 1≤l≤r≤N1 \leq l \leq r \leq N
  • 1≤k≤10151 \leq k \leq 10^{15}
  • All input values are integers.

样例 1 解释:
我们解释第一个查询。
首先,将 A1A_1 更新为 11。此时,A=(1,2,4,1,7,3,6)A=(1,2,4,1,7,3,6)。接下来,求解该子问题。
在该子问题中,共有四颗糖果,其美味值依次为 1,7,3,61,7,3,6。
为使所吃糖果的总美味值达到 k=9k=9 或更高,且所吃糖果数量最少,最优策略是吃下第二颗和第四颗糖果。因此,该子问题的答案为 22。

约束条件

  • 1≤N≤1051 \leq N \leq 10^5
  • 1≤Q≤1051 \leq Q \leq 10^5
  • 1≤Ai≤1091 \leq A_i \leq 10^9
  • 1≤c≤N1 \leq c \leq N
  • 1≤x≤1091 \leq x \leq 10^9
  • 1≤l≤r≤N1 \leq l \leq r \leq N
  • 1≤k≤10151 \leq k \leq 10^{15}
  • 所有输入值均为整数。

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

首页