#P3865. 【模板】ST 表 & RMQ 问题

    ID: 2804 远端评测题 800ms 125MiB 尝试: 1 已通过: 1 难度: 5 上传者: 标签>线段树树状数组O2优化st表,稀疏表

【模板】ST 表 & RMQ 问题

Description

Given a sequence of length NN and MM queries, for each query, find the maximum number in the specified interval.

Input Format

The first line contains two integers N,MN, M, representing the length of the sequence and the number of queries.

The second line contains NN integers (denoted as aia_i), representing the ii-th element of the sequence in order.

The next MM lines each contain two integers li,ril_i, r_i, indicating that the query interval is [li,ri][l_i, r_i].

Output Format

Output MM 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, 1N,M101 \le N, M \le 10.
  • For 70% of the testdata, 1N,M1051 \le N, M \le {10}^5.
  • For 100% of the testdata, 1N1051 \le N \le {10}^5, 1M2×1061 \le M \le 2 \times {10}^6, ai[0,109]a_i \in [0, {10}^9], 1liriN1 \le l_i \le r_i \le N.

Translated by ChatGPT 5