CF1523H.Hopping Around the Array

NOI/NOI+/CTSC

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

William really wants to get a pet. Since his childhood he dreamt about getting a pet grasshopper. William is being very responsible about choosing his pet, so he wants to set up a trial for the grasshopper!

The trial takes place on an array aa of length nn, which defines lengths of hops for each of nn cells. A grasshopper can hop around the sells according to the following rule: from a cell with index ii it can jump to any cell with indices from ii to i+aii+a_i inclusive.

Let's call the kk-grasshopper value of some array the smallest number of hops it would take a grasshopper to hop from the first cell to the last, but before starting you can select no more than kk cells and remove them from the array. When a cell is removed all other cells are renumbered but the values of aia_i for each cell remains the same. During this the first and the last cells may not be removed.

It is required to process qq queries of the following format: you are given three numbers ll, rr, kk. You are required to find the kk-grasshopper value for an array, which is a subarray of the array aa with elements from ll to rr inclusive.

威廉非常想养一只宠物。自童年起,他就梦想着养一只蚱蜢作为宠物。威廉在挑选宠物时非常负责任,因此他想为这只蚱蜢安排一次“试用期”!

这次试用期在一个长度为 nn 的数组 aa 上进行,该数组定义了每个单元格(共 nn 个)所对应的跳跃长度。蚱蜢可在这些单元格之间按如下规则跳跃:从下标为 ii 的单元格出发,它可以跳到任意一个下标在 ii 到 i+aii+a_i(含端点)范围内的单元格。

我们定义某个数组的 kk-蚱蜢值 为:蚱蜢从第一个单元格跳到最后一个单元格所需的最少跳跃次数;但在开始跳跃前,你最多可以从中移除 kk 个单元格。当某个单元格被移除后,其余单元格将重新编号(即下标连续),但每个单元格对应的 aia_i 值保持不变。注意:首尾两个单元格不可被移除。

现在需要处理 qq 个查询,每个查询给出三个整数 ll、rr、kk。你需要计算数组 aa 的子数组(即下标从 ll 到 rr(含端点)的所有元素构成的子数组)的 kk-蚱蜢值。

输入格式

The first line contains two integers nn and qq (1≤n,q≤200001 \le n, q \le 20000), the length of the array and the number of queries respectively.

The second line contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (1≤ai≤n1 \le a_i \le n) – the elements of the array.

The following qq lines contain queries: each line contains three integers ll, rr and kk (1≤l≤r≤n1 \le l \le r \le n, 0≤k≤min(30,r−l)0 \le k \le min(30, r-l)), which are the edges of the subarray and the number of the grasshopper value respectively.

第一行包含两个整数 nn 和 qq(1≤n,q≤200001 \le n, q \le 20000),分别表示数组的长度和查询次数。

第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(1≤ai≤n1 \le a_i \le n)—— 数组的元素。

接下来的 qq 行每行包含一个查询:每行包含三个整数 ll、rr 和 kk(1≤l≤r≤n1 \le l \le r \le n,0≤k≤min⁡(30,r−l)0 \le k \le \min(30, r-l)),分别表示子数组的左右边界以及蚱蜢值的序号。

输出格式

For each query print a single number in a new line — the response to a query.

对于每个查询,在新的一行中输出一个数字——该查询的答案。

输入输出样例

  • 输入#1

    9 5
    1 1 2 1 3 1 2 1 1
    1 1 0
    2 5 1
    5 9 1
    2 8 2
    1 9 4

    输出#1

    0
    2
    1
    2
    2

说明/提示

For the second query the process occurs like this:

For the third query the process occurs like this:

对于第二个查询,过程如下所示:

对于第三个查询,过程如下所示:

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

首页