for(int i=1; i<= N; i++)
{
num = Integer.parseInt(st.nextToken());
data[i] = num;
Node first = null, last = null;
while(!que.isEmpty()) // 조건 만족할때 가지 데크 뒤 빼기 ////////빼는 구간
{
last = que.peekLast();
if(last.num >= num) que.pollLast();
else break;
}
que.addLast(new Node(num, i));
int target = 0;
while(!que.isEmpty()) ///////////////////////////////// 넣는 구간
{
first = que.peekFirst();
last = que.peekLast();
target = first.num;
if(last.idx - first.idx < X)
{
break;
}
que.pollFirst();
}
}
https://www.acmicpc.net/problem/2003 // 투 포인터
https://www.acmicpc.net/problem/11003 ( 데크 사용!) // 슬라이딩 윈도우
슬라이딩 윈도우 (데크 이용)
ex) 11003 예시
빼줌
-데크의 뒤쪽 : 넣을 num 값 보다 같거나 크면 num 보다 작은 값 나올때까지 pollLast