模板题

#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 滑动窗口 单调队列的更多相关文章

  1. [POJ2823]Sliding Window 滑动窗口(单调队列)

    题意 刚学单调队列的时候做过 现在重新做一次 一个很经典的题目 现在有一堆数字共N个数字(N<=10^6),以及一个大小为k的窗口.现在这个从左边开始向右滑动,每次滑动一个单位,求出每次滑动后窗 ...

  2. Sliding Window(滑动窗口)

    Time Limit: 12000MS   Memory Limit: 65536K Total Submissions: 58002   Accepted: 16616 Case Time Limi ...

  3. 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 ...

  4. [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 ...

  5. POJ 2823 滑动窗口 单调队列

    https://vjudge.net/problem/POJ-2823 中文:https://loj.ac/problem/10175 题目 给一个长度为 $N$ 的数组,一个长为 $K$ 的滑动窗体 ...

  6. 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 ...

  7. [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 ...

  8. cogs 495. 滑动窗口 单调队列

    495. 滑动窗口 ★★   输入文件:window.in   输出文件:window.out   简单对比时间限制:2 s   内存限制:256 MB [问题描述] 给你一个长度为N的数组,一个长为 ...

  9. luoguP1886 滑动窗口 [单调队列]

    题目描述 现在有一堆数字共N个数字(N<=10^6),以及一个大小为k的窗口.现在这个从左边开始向右滑动,每次滑动一个单位,求出每次滑动后窗口中的最大值和最小值. 例如: The array i ...

随机推荐

  1. [Loading Component]Loading组件的v-model设计是否不合理?

    vue在2.4.2版本中给computed里的属性加了限制,详见assigning to a computed property without setter does not fail 项目将vue ...

  2. (2017.10.16) javascript 数据类型转换与操作

    javascript 有 5 种基本数据类型:undefined.null.Boolean.String.Number,还有1 种较复杂的数据类型 Object:各种类型之间可以相互转换,其中有些有趣 ...

  3. IOS使用固定定位遇到的问题

    近日需要实现移动端页面额外功能按钮,即点击加号弹出点赞与留言功能,通常这个按钮都会固定于页面的右下角,首先就想到使用固定定位来实现. 但是在测试时我们发现,在IOS中,当系统键盘弹出时,fixed会失 ...

  4. Java集合框架—Set

    集合框架 Set的特点:无序,不可以重复元素. (1)HashSet:数据结构是哈希表.线程是非同步的.               保证元素唯一性的原理:判断元素的hashCode值是否相同.   ...

  5. android中常见的设计模式有哪些?

    建造者模式 建造者模式最明显的标志就是Build类,而在Android中最常用的就是Dialog的构建,Notification的构建也是标准的建造者模式. 建造者模式很好理解,如果一个类的构造需要很 ...

  6. SQL 中的group by (转载)

    概述 原始表 简单Group By Group By 和 Order By Group By中Select指定的字段限制 Group By All Group By与聚合函数 Having与Where ...

  7. Installing Apache, PHP, and MySQL on Mac OS X

    I have installed Apache, PHP, and MySQL on Mac OS X since Leopard. Each time doing so by hand. Each ...

  8. Red Hat Enterprise Linux(RHEL)中yum的repo文件详解

    Yum(全称为 Yellow dog Updater, Modified)是一个在Fedora和RedHat以及CentOS中的Shell前端软件包管理器.基于RPM包管理,能够从指定的服务器自动下载 ...

  9. 解除phpMyAdmin导入大型MySQL数据库文件大小限制

    phpMyAdmin 导入大型数据库文件大小限制配置… 1. 修改 php.ini 文件中下列3项的值: upload_max_filesize, memory_limit 和 post_max_si ...

  10. mysql如何让自增id从1开始设置方法

    有两种方式 第一种: 如果表中数据没有用.如果直接删除数据,自动增长ID还是不会从1开始的,可以利用“清空数据表”.这样自动增长ID也将会从1开始. 清空表的sql如下 truncate table ...