CF840D.Destiny

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

Once, Leha found in the left pocket an array consisting of nn integers, and in the right pocket qq queries of the form ll rr kk . If there are queries, then they must be answered. Answer for the query is minimal xx such that xx occurs in the interval ll rr strictly more than times or 1-1 if there is no such number. Help Leha with such a difficult task.

输入格式

First line of input data contains two integers nn and qq ( 1<=n,q<=31051<=n,q<=3 \cdot 10^{5} ) — number of elements in the array and number of queries respectively.

Next line contains nn integers a1,a2,...,ana_{1},a_{2},...,a_{n} ( 1<=ai<=n1<=a_{i}<=n ) — Leha's array.

Each of next qq lines contains three integers ll , rr and kk ( 1<=l<=r<=n,2<=k<=51<=l<=r<=n,2<=k<=5 ) — description of the queries.

输出格式

Output answer for each query in new line.

输入输出样例

  • 输入#1

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

    输出#1

    1
    -1
    
  • 输入#2

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

    输出#2

    2
    1
    2
    
首页