luogu#P3865. 【模板】ST 表 & RMQ 问题
【模板】ST 表 & RMQ 问题
Background
This is a classic ST table problem — static range maximum.
Please note that the maximum time limit for the largest testdata is only 0.8 s, and the data is not weak. Please ensure that the time complexity per query is . If you use a higher time complexity algorithm, it is not guaranteed to pass.
If you believe your code has the correct time complexity but gets TLE, you can try fast input:
inline int read()
{
int x=0,f=1;char ch=getchar();
while (ch<'0'||ch>'9'){if (ch=='-') f=-1;ch=getchar();}
while (ch>='0'&&ch<='9'){x=x*10+ch-48;ch=getchar();}
return x*f;
}
The function returns the first integer read.
Fast input is only for speeding up input and is not mandatory.
Problem Description
Given a sequence of length and queries, for each query, find the maximum number in the specified interval.
Input Format
The first line contains two integers , representing the length of the sequence and the number of queries.
The second line contains integers (denoted as ), representing the -th element of the sequence in order.
The next lines each contain two integers , indicating that the query interval is .
Output Format
Output lines, each containing one integer, representing the answer to each query in order.
8 8
9 3 1 7 5 6 0 8
1 6
1 5
2 7
2 6
1 8
4 8
3 7
1 8
9
9
7
7
9
8
7
9
Hint
- For 30% of the testdata, .
- For 70% of the testdata, .
- For 100% of the testdata, , , , .
Translated by ChatGPT 5