poj2823 Sliding Window luogu1886 滑动窗口 单调队列
模板题
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
int l1=1, r1, l2=1, r2, q1[1000005], q2[1000005], a[1000005], n, k;
int ans1[1000005], ans2[1000005];
void rn(int &x){
char ch=getchar();
int f=1;
while(ch<'0' || ch>'9'){
if(ch=='-') f = -1;
ch = getchar();
}
while(ch>='0' && ch<='9'){
x = x * 10 + ch - '0';
ch = getchar();
}
x *= f;
}
int main(){
rn(n);rn(k);
for(int i=1; i<=n; i++){
while(l1<=r1 && q1[l1]<=i-k) l1++;
while(l2<=r2 && q2[l2]<=i-k) l2++;
rn(a[i]);
while(l1<=r1 && a[q1[r1]]>a[i]) r1--;
q1[++r1] = i;
while(l2<=r2 && a[q2[r2]]<a[i]) r2--;
q2[++r2] = i;
ans1[i] = a[q1[l1]];
ans2[i] = a[q2[l2]];
}
for(int i=k; i<=n; i++) printf("%d ", ans1[i]);
putchar('\n');
for(int i=k; i<=n; i++) printf("%d ", ans2[i]);
return 0;
}
poj2823 Sliding Window luogu1886 滑动窗口 单调队列的更多相关文章
- [POJ2823]Sliding Window 滑动窗口(单调队列)
题意 刚学单调队列的时候做过 现在重新做一次 一个很经典的题目 现在有一堆数字共N个数字(N<=10^6),以及一个大小为k的窗口.现在这个从左边开始向右滑动,每次滑动一个单位,求出每次滑动后窗 ...
- Sliding Window(滑动窗口)
Time Limit: 12000MS Memory Limit: 65536K Total Submissions: 58002 Accepted: 16616 Case Time Limi ...
- POJ 2823 滑动窗口 单调队列模板
我们从最简单的问题开始: 给定一个长度为N的整数数列a(i),i=0,1,...,N-1和窗长度k. 要求: f(i) = max{a(i-k+1),a(i-k+2),..., a(i)},i = 0 ...
- [LeetCode] Sliding Window Maximum 滑动窗口最大值
Given an array nums, there is a sliding window of size k which is moving from the very left of the a ...
- POJ 2823 滑动窗口 单调队列
https://vjudge.net/problem/POJ-2823 中文:https://loj.ac/problem/10175 题目 给一个长度为 $N$ 的数组,一个长为 $K$ 的滑动窗体 ...
- POJ - 2823 Sliding Window (滑动窗口入门)
An array of size n ≤ 10 6 is given to you. There is a sliding window of size kwhich is moving from t ...
- [LeetCode] 239. Sliding Window Maximum 滑动窗口最大值
Given an array nums, there is a sliding window of size k which is moving from the very left of the a ...
- cogs 495. 滑动窗口 单调队列
495. 滑动窗口 ★★ 输入文件:window.in 输出文件:window.out 简单对比时间限制:2 s 内存限制:256 MB [问题描述] 给你一个长度为N的数组,一个长为 ...
- luoguP1886 滑动窗口 [单调队列]
题目描述 现在有一堆数字共N个数字(N<=10^6),以及一个大小为k的窗口.现在这个从左边开始向右滑动,每次滑动一个单位,求出每次滑动后窗口中的最大值和最小值. 例如: The array i ...
随机推荐
- 使用AuthToken架构保护用户帐号验证Cookie的安全性
在项目或者网站开发中,我们很多人很多时候喜欢使用微软的FormsAuthentication类的GetAuthCookie函数生成需要在访客客户端放置的帐号校验Cookie,这个本身没问题,但是很多人 ...
- layout_weight属性
layout_weight 某个控件text多行,第一行对齐,baselineAligned = "false" 可使控件对齐 weight 计算规则 剩余尺寸=父布局尺寸-子布局 ...
- 读写属性/if判断那点事/数组
读写属性属性操作注意事项 js中不允许出现"-".所以font-size变成fontSize/margin-top变成marginTop. Op.style.with=" ...
- 1.2 the structure of a compiler
Compiler 1.2 the structure of a compiler Compiler : analysis and synthesis syntactically 语法上的 sema ...
- npm在linux即mac下更新时报错
nam在linux即mac下需要更新到新版本:
- (五)SpringMVC之使用Kaptcha实现验证码功能
一.什么是Kaptcha Kaptcha是Google开发的用于自动生成验证码的插件. 二.怎么导入Kaptcha ① 如果没有用Maven管理工具的话就直接导入包(可以直接下载:pau8) http ...
- HDU 5094 Maze (状压)
加一个维度,钥匙的状态,状压一下.n很小,钥匙也只有10个,bfs就好了. 忘了数组初始化.以后坚决不犯这种低级错误. #include<cstdio> #include<queue ...
- 使用Python-OpenCV向图片添加噪声(高斯噪声、椒盐噪声)
在matlab中,存在执行直接得函数来添加高斯噪声和椒盐噪声.Python-OpenCV中虽然不存在直接得函数,但是很容易使用相关的函数来实现. 代码: import numpy as np impo ...
- 用函数求lnx,lgx等
https://blog.csdn.net/liujian20150808/article/details/50628061
- tcp、http和socket的区别
本文原链接:https://www.jianshu.com/p/88d69454bdde tcp.http和socket的区别 一:tcp协议 tcp协议属于传输层协议(UDP也属于传输层协议,但是U ...