没调出来,求助
查看原帖
没调出来,求助
386984
kd_homelander915楼主2023/9/29 16:48
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<cmath>
#include<vector>
#include<queue>
#include<deque>
using namespace std;
typedef long long ll;
int n,k,a[1000005],q[1000005],h=1,r;
template <typename T>
void in(T &x){
	char c=getchar();
	bool f=true;
	for(;c<'0'||c>'9';c=getchar())
		if(c=='-')
		    f=false;
	for(x=0;c>='0'&&c<='9';c=getchar())
		x=(x<<1)+(x<<3)+(c^48);
	if(!f)
	    x=-x;
}
void putf(int x){
	if(x<0)
	    x=-x,putchar('-');
	if(x>9)
	    putf(x/10);
	putchar((x%10)^48);
}
int main(){
//    freopen(".in","r",stdin);
//    freopen(".out","w",stdout);
//	ios::sync_with_stdio(false);
//	cin.tie(0);
//	cout.tie(0);
    in(n);
    in(k);
    for(int i=1;i<=n;i++)
	    in(a[i]);
	q[++r]=1;
	if(k==1)
	    printf("1\n");
	for(int i=2;i<=n;i++){
		while(q[r]<i-k+1&&h<=r)
		    h++;
		while(a[i]>=a[q[r]]&&h<=r)
		    r--;
		q[++r]=i;
		if(i>=k)
		    printf("%d\n",r-h+1);
	}
	return 0;
}
2023/9/29 16:48
加载中...