ACM 正负大数的读入外挂模板+单调队列模板


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#define PI acos(-1.0)
#define LINF 1000000000000000000LL
#define eps 1e-8
#define LL long long
#define MAXN 1000010 
using namespace std;
const int INF=0x3f3f3f3f;
LL read()
{
	LL x=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9')
	{
		if(ch=='-')
			f=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9')
	{
		x=x*10+ch-'0';
		ch=getchar();
	}
	return x*f;
}
LL n,k;
LL a[MAXN],q1[MAXN],q2[MAXN],ans1[MAXN],ans2[MAXN];//q1:单调递增队列 q2:单调递减队列 
int l1=1,l2=1,r1,r2;  
int main()
{
	n=read();
	k=read();
	//scanf("%lld%lld",&n,&k);
	for(int i=1;i<=n;i++)
		a[i]=read();
	for(int i=1;i<=n;i++)
	{
		while(l1<=r1&&q1[l1]<=i-k) l1++;
		while(l2<=r2&&q2[l2]<=i-k) l2++;
		while(l1<=r1&&a[i]<a[q1[r1]]) r1--;
		q1[++r1]=i;
		while(l2<=r2&&a[i]>a[q2[r2]]) r2--;
		q2[++r2]=i;
		ans1[i]=a[q1[l1]];
		ans2[i]=a[q2[l2]];
	}
	for(int i=k;i<=n;i++) printf("%lld ",ans1[i]);
	puts("");
	for(int i=k;i<=n;i++) printf("%lld ",ans2[i]);
	puts("");
	return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

林下的码路

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值