CM_Silence @ 2024-02-02 17:28:30
有5个MLE,还有一个有时MLE有时不MLE的,难绷。后悔拿java写了,但是我见到有大佬拿java过的qaq
/**
* @author CM_Silence
*/
import java.util.*;
public class Main {
public static void main(String[] args) {
Deque<Integer> dq = new ArrayDeque<Integer>();
int[] arr = new int[2000005];
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int m = sc.nextInt();
for(int i = 1; i <= n; i++) {
arr[i] = sc.nextInt();
}
sc.close();
//反正第一次肯定输出0,不写在循环里面了
System.out.println(0);
for (int i = 1; i < n; i++) {
//去尾
while(!dq.isEmpty() && arr[dq.peekLast()] > arr[i]) {
dq.pollLast();
}
//入队
dq.offerLast(i);
//删头
while(!dq.isEmpty() && dq.peekFirst() <= i - m) {
dq.pollFirst();
}
System.out.println(arr[dq.peekFirst()]);
}
}
}
by NCUJACK @ 2024-02-16 22:19:28
ST表爆了MLE,WWW