poj2823 Sliding Window luogu1886 滑动窗口 单调队列
2024-10-21 10:07:48
模板题
#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;
}
最新文章
- Linux 下EXT2文件系统 —— 如何将蚂蚁和大象优雅的装进冰箱里
- PDF2
- 使用 PowerShell 自动登录Azure
- apt-get常见错误——Unmet dependencies
- std::vector介绍
- Windows通用应用开发手记-Behavior SDK概述
- 并查集+关系的传递(poj 1182)
- java按行读取txt并按行写入
- iOS之RunTime浅谈
- Cognos 多维源目录树的任何单个维度中显示的最大项目数(默认为50)的设置规则
- Windows下Mysql解压缩版配置安装与卸载
- CDZSC_2015寒假新人(1)——基础 i
- IIS7.5 用 IIS AppPool\应用程序池名 做账号 将各站点权限分开
- Spring Security Filter详解
- [Linux] nginx管理员指南基本功能
- 从 Aliyun 经典网络迁移到 Aliyun VPC 网络
- android:ViewHolder模式
- php打乱数组二维数组、多维数组
- Python自动化开发 - select模块
- UVA540-队列
热门文章
- Java语法基础(2)
- Kendo MVVM 数据绑定(七) Invisible/Visible
- ThreadLocal的内存泄露
- COGS 2342. [SCOI2007]kshort
- Caused by: java.lang.IllegalStateException: javax.websocket.server.ServerContainer not available
- 【转】NSBundle的使用,注意mainBundle和Custom Bundle的区别
- @Param注解在dao层的使用
- js中异步方案比较完整版(callback,promise,generator,async)
- 《毛毛虫组》【Alpha】Scrum meeting 4
- 瀑布流封装(仿写UITableView)