Codeforces Round 276 (Div. 1)
E
Sign on Fence
Codeforces
2500
原题
← D→
翻译中…

Bizon the Champion has recently finished painting his wood fence. The fence consists of a sequence of $*n*$ panels of $1$ meter width and of arbitrary height. The $*i*$-th panel's height is $*h*_{*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 $*w*$ meters.
  2. The sign must fit into the segment of the fence from the $*l*$-th to the $*r*$-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.

翻译中…

Input

翻译中…

The first line of the input contains integer $*n*$ — the number of panels in the fence ($1 ≤ *n* ≤ 10^{5}$).

翻译中…

The second line contains $*n*$ space-separated integers $*h*_{*i*}$, — the heights of the panels ($1 ≤ *h*_{*i*} ≤ 10^{9}$).

翻译中…

The third line contains an integer $*m*$ — the number of the queries ($1 ≤ *m* ≤ 10^{5}$).

翻译中…

The next $*m*$ lines contain the descriptions of the queries, each query is represented by three integers $*l*$, $*r*$ and $*w*$ ($1 ≤ *l* ≤ *r* ≤ *n*$, $1 ≤ *w* ≤ *r* - *l* + 1$) — the segment of the fence and the width of the sign respectively.

翻译中…

Output

翻译中…

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.

翻译中…

Note

翻译中…

The fence described in the sample looks as follows:

翻译中…

image

翻译中…

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

翻译中…

image The optimal position of the sign for the first query.

翻译中…

image The optimal position of the sign for the second query.

翻译中…

image The optimal position of the sign for the third query.

翻译中…

样例

Input #1
5
1 2 2 3 3
3
2 5 3
2 5 2
1 5 5
Output #1
2
3
1
InputCopy OutputCopy
题目信息
题号
484E
时间限制
4 s
内存限制
256 MB
标签
二分
构造
数据结构

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。