看我的,别相信楼下的,Ta的是关机代码

~Oo爆米花oO~  •  6个月前


include <bits/stdc++.h>

using namespace std; int a[2000001]; int main(){

deque<int>q;
int n,l = 1,r = 1,k;
cin >> n >> k;
for(int i = 1;i <= n;i++){
	cin >> a[i];
}
q.push_back(1);
while(r <= n){
	if(r - l + 1 == k){
		cout << a[q.front()] << " ";
		l++;
		if(l > q.front()){
			q.pop_front();
		}
	}
	else{
		r++;
		while(!q.empty() && a[q.back()] >= a[r]){
			q.pop_back();
		}
		q.push_back(r);
	}
}	
cout << endl;
q.clear();
r = l = 1;
q.push_back(1);
while(r <= n){
	if(r - l + 1 == k){
		cout << a[q.front()] << " ";
		l++;
		if(l > q.front()){
			q.pop_front();
		}
	}
	else{
		r++;
		while(!q.empty() && a[q.back()] <= a[r]){
			q.pop_back();
		}
		q.push_back(r);
	}
}
return 0;

}


评论:

请先登录,才能进行评论