CF484E.Sign on Fence

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

Bizon the Champion has recently finished painting his wood fence. The fence consists of a sequence of nn panels of 11 meter width and of arbitrary height. The ii -th panel's height is hih_{i} meters. The adjacent planks follow without a gap between them.

After Bizon painted the fence he decided to put a "for sale" sign on it. The sign will be drawn on a rectangular piece of paper and placed on the fence so that the sides of the sign are parallel to the fence panels and are also aligned with the edges of some panels. Bizon the Champion introduced the following constraints for the sign position:

  1. The width of the sign should be exactly ww meters.
  2. The sign must fit into the segment of the fence from the ll -th to the rr -th panels, inclusive (also, it can't exceed the fence's bound in vertical direction).

The sign will be really pretty, So Bizon the Champion wants the sign's height to be as large as possible.

You are given the description of the fence and several queries for placing sign. For each query print the maximum possible height of the sign that can be placed on the corresponding segment of the fence with the given fixed width of the sign.

输入格式

The first line of the input contains integer nn~--- the number of panels in the fence (1n1051 \leq n \leq 10^{5}).

The second line contains nn space-separated integers hih_{i}, --- the heights of the panels (1hi1091 \leq h_{i} \leq 10^{9}).

The third line contains an integer mm --- the number of the queries (1m1051 \leq m \leq 10^{5}).

The next mm lines contain the descriptions of the queries, each query is represented by three integers ll, rr and ww (1lrn1 \leq l \leq r \leq n, 1wrl+11 \leq w \leq r-l+1) --- the segment of the fence and the width of the sign respectively.

输出格式

For each query print the answer on a separate line — the maximum height of the sign that can be put in the corresponding segment of the fence with all the conditions being satisfied.

输入输出样例

  • 输入#1

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

    输出#1

    2
    3
    1
    

说明/提示

The fence described in the sample looks as follows:

The possible positions for the signs for all queries are given below.

The optimal position of the sign for the first query. The optimal position of the sign for the second query. The optimal position of the sign for the third query.

首页