CF1876G.Clubstep

普及/提高-

通过率:0%

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 1kp11 \leq k \leq p-1 and it does not reach any part kk for all p+1knp+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 1kp11 \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 ( ljprjl_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.

输入格式

The first line contains a single integer nn ( 1n31051 \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 ( 1ai1091\leq a_i\leq10^9 ) — Chaneka's familiarity value with each part.

The third line contains a single integer qq ( 1q31051\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 ( 1ljrjn1\leq l_j\leq r_j\leq n ; 1xj1091\leq x_j\leq10^9 ) — the description of the jj -th question.

输出格式

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 ( ljprjl_j \leq p \leq r_j ) is at least 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 .

首页