Codeforces Round 429 (Div. 1)
D
Destiny
Codeforces
2500
原题
← CE →
翻译中…

Once, Leha found in the left pocket an array consisting of $*n*$ integers, and in the right pocket $*q*$ queries of the form $*l*$ $*r*$ $*k*$. If there are queries, then they must be answered. Answer for the query is minimal $*x*$ such that $*x*$ occurs in the interval $*l*$ $*r*$ strictly more than image times or $- 1$ if there is no such number. Help Leha with such a difficult task.

翻译中…

Input

翻译中…

First line of input data contains two integers $*n*$ and $*q*$ ($1 ≤ *n*, *q* ≤ 3·10^{5}$) — number of elements in the array and number of queries respectively.

翻译中…

Next line contains $*n*$ integers $*a*_{1}, *a*_{2}, ..., *a*_{*n*}$ ($1 ≤ *a*_{*i*} ≤ *n*$) — Leha's array.

翻译中…

Each of next $*q*$ lines contains three integers $*l*$, $*r*$ and $*k*$ ($1 ≤ *l* ≤ *r* ≤ *n*, 2 ≤ *k* ≤ 5$) — description of the queries.

翻译中…

Output

翻译中…

Output answer for each query in new line.

翻译中…

样例

Input #1
4 2
1 1 2 2
1 3 2
1 4 2
Output #1
1
-1
InputCopy OutputCopy
Input #2
5 3
1 2 1 3 2
2 5 3
1 2 3
5 5 2
Output #2
2
1
2
InputCopy OutputCopy
题目信息
题号
840D
时间限制
2.5 s
内存限制
512 MB
标签
数据结构
概率论

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