莫名 RE 求条
查看原帖
莫名 RE 求条
629377
iamajcer楼主2025/7/24 18:41

为啥 RE 了???RE #1。不知道为什么。

#include <bits/stdc++.h>
using namespace std;
const int N=1e6+5;

int n, a[N], G, d, f[N], hh=0, tt=0, q[N];
int main()
{
	scanf("%d", &n);
	for (int i=1; i<=n; i++) scanf("%d", &a[i]);
	scanf("%d", &G);
	while (G--)
	{
		scanf("%d", &d);
		
		f[1]=0, q[++tt]=1, hh=tt;
		for (int i=2; i<=n; i++)
		{
			while (hh<=tt && q[hh]<i-d) hh++;
			f[i]=f[q[hh]]+(a[i]>=a[q[hh]]);
			
			while (hh<=tt && (f[q[tt]]>f[i] || (f[q[tt]]==f[i] && a[q[tt]]<=a[i]))) tt--;
			q[++tt]=i;
		}
		
		printf("%d\n", f[n]);
	}
	return 0;
}
2025/7/24 18:41
加载中...