for(int i=2;i<=m;i++){
if(i-q1[head1]>=n) head1++;
if(i-q2[head2]>=n) head2++;
while(head1<=tail1&&a[q1[tail1]]<=a[i]) tail1--;
while(head2<=tail2&&a[q2[tail2]]>=a[i]) tail2--;
tail1++,q1[tail1]=i;
tail2++,q2[tail2]=i;
if(i>=n){
ans++;
ans1[ans]=a[q1[head1]];ans2[ans]=a[q2[head2]];
}
}