Balanced Lineup POJ-3264(線分樹は一番価値のある水を求める)
3000 ワード
Balanced Lineup
POJ-3264
For the daily milking,Farmer John's N cows(1≦ N ≦50,000)alwaysラインナップup in the same order.One day Farmer John decides to organize a game of Ultime Fribee with some of the cows.To keep things simple,he will tare the contigugyou.Holt the from line the.
Farmer John has made a list of Q (1≦ Q ≦200,000)potental groups of cows and their heights(1≦ height ≤1,000,000).For each group,he wants your help to determine the difference in height bertween the shot and the tallest cow in the group.
Input
Line 1:Two space-separated integers、 N and Q.Lines 2. N+1:Line i+1 contains a single integer that is the height of cow i リンス N+2. N+ Q+1:Two integers A and B (1≦A ≦ B ≦ N)representing the range of cows from A ト B inclusive.
Output
Lines 1. Q:Each LINE contains a single integer that is a reponse to a reply and indicates the difference in height between the tallest and shotest cow in the range.
Sample Input
構想:線分樹の水の題
ACコード:
POJ-3264
For the daily milking,Farmer John's N cows(1≦ N ≦50,000)alwaysラインナップup in the same order.One day Farmer John decides to organize a game of Ultime Fribee with some of the cows.To keep things simple,he will tare the contigugyou.Holt the from line the.
Farmer John has made a list of Q (1≦ Q ≦200,000)potental groups of cows and their heights(1≦ height ≤1,000,000).For each group,he wants your help to determine the difference in height bertween the shot and the tallest cow in the group.
Input
Line 1:Two space-separated integers、 N and Q.Lines 2. N+1:Line i+1 contains a single integer that is the height of cow i リンス N+2. N+ Q+1:Two integers A and B (1≦A ≦ B ≦ N)representing the range of cows from A ト B inclusive.
Output
Lines 1. Q:Each LINE contains a single integer that is a reponse to a reply and indicates the difference in height between the tallest and shotest cow in the range.
Sample Input
6 3
1
7
3
4
2
5
1 5
4 6
2 2
Sample Output6
3
0
n個の数、m個の操作を与え、毎回の操作でx-y区間の最大の差を求める.構想:線分樹の水の題
ACコード:
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include