25pts求调QAQ玄关
查看原帖
25pts求调QAQ玄关
1045387
Kobe_BryantQAQ楼主2025/1/7 20:00

rt,玄关

#include<bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
long long n, k, a[N];
deque<long long> q;
int main() {
	cin >> n >> k;
	for(int i = 1; i <= n; i ++) {
		cin >> a[i];
	}
	for(int i = 1; i <= n; i ++) {
		while(!q.empty() && a[q.back()] <= a[i]){
			q.pop_back();
		}
		q.push_back(i);
		while(!q.empty() && q.front() + k <= i){
			q.pop_front();
		}
		if(i >= k){
			cout << q.size() << '\n';
		}
	}
	return 0;
}
2025/1/7 20:00
加载中...