CF1876G.Clubstep

NOI/NOI+/CTSC

通过率:0%

时间限制:3.00s

内存限制:1024MB

AC君温馨提醒

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

题目描述

There is an extremely hard video game that is one of Chaneka's favourite video games. One of the hardest levels in the game is called Clubstep. Clubstep consists of nn parts, numbered from 11 to nn. Chaneka has practised the level a good amount, so currently, her familiarity value with each part ii is aia_i.

After this, Chaneka can do several (possibly zero) attempts on Clubstep. In each attempt, she dies on one of the nn parts. If an attempt dies on part pp, that means it only successfully passes through every part kk for all 1≤k≤p−11 \leq k \leq p-1 and it does not reach any part kk for all p+1≤k≤np+1 \leq k \leq n. An attempt that dies on part pp takes pp seconds.

It is known that Chaneka improves much more on the part she dies on than anything else. It is also known that during an attempt, Chaneka does not get to practise that much on the parts she does not reach. So, the effect of an attempt that dies on part pp is as follows:

  • Chaneka's familiarity value with part pp increases by 22.
  • Chaneka's familiarity value with each part kk for all 1≤k≤p−11 \leq k \leq p-1 increases by 11.

There will be qq questions. For the jj-th question, you are given three integers ljl_j, rjr_j, and xjx_j. Then, you are asked to find out the minimum time (in seconds) for Chaneka to make it such that the familiarity value for every part pp (lj≤p≤rjl_j \leq p \leq r_j) is at least xjx_j.

Note that each question is independent, so the attempt Chaneka does on a question does not affect the familiarity values of any other questions.

有一款极其困难的电子游戏,是Chaneka最喜爱的电子游戏之一。游戏中最难的关卡之一名为“Clubstep”。Clubstep由 nn 个部分组成,编号从 11 到 nn。Chaneka 已经对该关卡进行了大量练习,因此目前她对每个部分 ii 的熟悉度值为 aia_i。

此后,Chaneka 可以进行若干次(可能为零次)Clubstep 尝试。在每次尝试中,她会在 nn 个部分中的某一个部分失败。若一次尝试在第 pp 部分失败,则意味着该尝试成功通过了所有满足 1≤k≤p−11 \leq k \leq p-1 的部分 kk,但未能到达任何满足 p+1≤k≤np+1 \leq k \leq n 的部分 kk。在第 pp 部分失败的一次尝试耗时 pp 秒。

已知 Chaneka 在她失败的部分所获得的进步远超其他任何部分;同时也已知,在一次尝试过程中,她对未能到达的部分几乎无法进行有效练习。因此,在第 pp 部分失败的一次尝试会产生如下效果:

  • Chaneka 对第 pp 部分的熟悉度值增加 22;
  • Chaneka 对每个满足 1≤k≤p−11 \leq k \leq p-1 的部分 kk 的熟悉度值各增加 11。

接下来会有 qq 个询问。对于第 jj 个询问,给出三个整数 ljl_j、rjr_j 和 xjx_j。你需要求出:使得所有满足 lj≤p≤rjl_j \leq p \leq r_j 的部分 pp 的熟悉度值均至少达到 xjx_j 所需的最少时间(单位:秒)。

注意:每个询问相互独立,即 Chaneka 在某个询问中进行的尝试不会影响其他询问中的熟悉度值。

输入格式

The first line contains a single integer nn (1≤n≤3⋅1051 \leq n \leq 3\cdot10^5) — the number of parts in Clubstep.

The second line contains nn integers a1,a2,a3,…,ana_1,a_2,a_3,\ldots,a_n (1≤ai≤1091\leq a_i\leq10^9) — Chaneka's familiarity value with each part.

The third line contains a single integer qq (1≤q≤3⋅1051\leq q\leq3\cdot10^5) — the number of questions.

The jj-th of the next qq lines contains three integers ljl_j, rjr_j, and xjx_j (1≤lj≤rj≤n1\leq l_j\leq r_j\leq n; 1≤xj≤1091\leq x_j\leq10^9) — the description of the jj-th question.

第一行包含一个整数 nn(1≤n≤3⋅1051 \leq n \leq 3\cdot10^5)—— Clubstep 的部分数量。

第二行包含 nn 个整数 a1,a2,a3,…,ana_1,a_2,a_3,\ldots,a_n(1≤ai≤1091\leq a_i\leq10^9)—— Chaneka 对每个部分的熟悉度值。

第三行包含一个整数 qq(1≤q≤3⋅1051\leq q\leq3\cdot10^5)—— 问题的数量。

接下来的 qq 行中,第 jj 行包含三个整数 ljl_j、rjr_j 和 xjx_j(1≤lj≤rj≤n1\leq l_j\leq r_j\leq n;1≤xj≤1091\leq x_j\leq10^9)—— 第 jj 个问题的描述。

输出格式

Output qq lines with an integer in each line. The integer in the jj-th line represents the minimum time (in seconds) for Chaneka to make it such that the familiarity value for every part pp (lj≤p≤rjl_j \leq p \leq r_j) is at least xjx_j.

输出 qq 行,每行一个整数。第 jj 行的整数表示 Chaneka 所需的最少时间(单位:秒),使得每个部分 pp(其中 lj≤p≤rjl_j \leq p \leq r_j)的熟悉度值均至少为 xjx_j。

输入输出样例

  • 输入#1

    5
    1 3 2 1 2
    3
    1 5 5
    2 4 5
    3 3 1

    输出#1

    15
    11
    0

说明/提示

For the 11-st question, one possible strategy is to do the following:

  1. Do 11 attempt that dies on part 11. This takes 11 second. The familiarity values become [3,3,2,1,2][3, 3, 2, 1, 2].
  2. Do 11 attempt that dies on part 44. This takes 44 seconds. The familiarity values become [4,4,3,3,2][4, 4, 3, 3, 2].
  3. Do 22 attempts that die on part 55. This takes 1010 seconds. The familiarity values become [6,6,5,5,6][6, 6, 5, 5, 6].

The total time taken (in seconds) is 1+4+10=151+4+10=15.

For the 22-nd question, one possible strategy is to do the following:

  1. Do 11 attempt that dies on part 33. This takes 33 seconds. The familiarity values become [2,4,4,1,2][2, 4, 4, 1, 2].
  2. Do 22 attempts that die on part 44. This takes 88 seconds. The familiarity values become [4,6,6,5,2][4, 6, 6, 5, 2].

The total time taken (in seconds) is 3+8=113+8=11.

对于第 11 个问题,一种可能的策略如下:

  1. 执行 11 次在第 11 部分失败的尝试。耗时 11 秒。熟悉度值变为 [3,3,2,1,2][3, 3, 2, 1, 2]。
  2. 执行 11 次在第 44 部分失败的尝试。耗时 44 秒。熟悉度值变为 [4,4,3,3,2][4, 4, 3, 3, 2]。
  3. 执行 22 次在第 55 部分失败的尝试。耗时 1010 秒。熟悉度值变为 [6,6,5,5,6][6, 6, 5, 5, 6]。

总耗时(单位:秒)为 1+4+10=151+4+10=15。

对于第 22 个问题,一种可能的策略如下:

  1. 执行 11 次在第 33 部分失败的尝试。耗时 33 秒。熟悉度值变为 [2,4,4,1,2][2, 4, 4, 1, 2]。
  2. 执行 22 次在第 44 部分失败的尝试。耗时 88 秒。熟悉度值变为 [4,6,6,5,2][4, 6, 6, 5, 2]。

总耗时(单位:秒)为 3+8=113+8=11。

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

首页