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)