"POJ2761" "section K big" Feed The Dogs (spit Groove)

Source: Internet
Author: User

Description

Wind loves pretty dogs very much, and she had n pet dogs. So Jiajia have to feed the dogs every day for wind. Jiajia loves wind, and not the dogs, so Jiajia use a special the-to feed the dogs. At lunchtime, the dogs would stand on one line, numbered from 1 to N, the leftmost one is 1, the second one is 2, and so on . In each feeding, Jiajia choose a inteval[i,j], select the k-th pretty dog to feed. Of course Jiajia have his own a-deciding, the pretty value of each dog. It should is noted that Jiajia does not want to feeds any position too much, because it may cause some death of dogs. If So, wind would be angry and the aftereffect would be serious. Hence Any feeding inteval won't contain another completely, though the intervals may intersect with each of the other.

Your task is to help Jiajia calculate which dog ate the food after each feeding.

Input

The first line contains N and m, indicates the number of dogs and the number of feedings.

The second line contains n integers, and describe the pretty value of each of the dog from left to right. You should notice, the dog with lower pretty, value is prettier.

Each of following m lines contain three integer i,j,k, it means that Jiajia feed the k-th pretty dog in this feeding.

You can assume that n<100001 and m<50001.

Output

Output file has m lines. The i-th line should contain the pretty value of the dog, who got the food in the i-th feeding.

Sample Input

7 21 5 2 6 3 7 41 5 32 7 1

Sample Output

32

Source

POJ Monthly--2006.02.26,zgl & TWB "Analysis" see someone said with Treap do interval k big, I startled, function type treap! orzzz, then a look at the topic, a look at the code. Topic (interval disjoint)--useful, huh? Code-Sort the interval, insert each one, and then delete each section, for each interval to seek the k ... Lying trough, this is also called Interval K big! You're teasing me. (╯‵-′) ╯︵┻━┻

"POJ2761" "section K big" Feed The Dogs (spit Groove)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.