AcWing Problem 1275 - 最大数
题目类型:线段树
题意
有两种操作:
• 添加操作:每次向序列后添加一个数
• 询问这个序列中最后 L L L 个数中最大值
分析
因为每次插入的数与上一次查询有关系所以必须动态在线做这题。求区间最大值可以想到用线段树,起初可认为线段树的叶子节点都为 0 0 0,然后每次添加一个数的时候再进行更新并维护最大值。
代码
static int[] C;
public static void solve() throws IOException {
int m = nextInt();
int p = nextInt();
init(m);
int temp = 0;
int n = m, size = 0;
while (m-- > 0<