模板题

#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;
}

最新文章

  1. Linux 下EXT2文件系统 —— 如何将蚂蚁和大象优雅的装进冰箱里
  2. PDF2
  3. 使用 PowerShell 自动登录Azure
  4. apt-get常见错误——Unmet dependencies
  5. std::vector介绍
  6. Windows通用应用开发手记-Behavior SDK概述
  7. 并查集+关系的传递(poj 1182)
  8. java按行读取txt并按行写入
  9. iOS之RunTime浅谈
  10. Cognos 多维源目录树的任何单个维度中显示的最大项目数(默认为50)的设置规则
  11. Windows下Mysql解压缩版配置安装与卸载
  12. CDZSC_2015寒假新人(1)——基础 i
  13. IIS7.5 用 IIS AppPool\应用程序池名 做账号 将各站点权限分开
  14. Spring Security Filter详解
  15. [Linux] nginx管理员指南基本功能
  16. 从 Aliyun 经典网络迁移到 Aliyun VPC 网络
  17. android:ViewHolder模式
  18. php打乱数组二维数组、多维数组
  19. Python自动化开发 - select模块
  20. UVA540-队列

热门文章

  1. Java语法基础(2)
  2. Kendo MVVM 数据绑定(七) Invisible/Visible
  3. ThreadLocal的内存泄露
  4. COGS 2342. [SCOI2007]kshort
  5. Caused by: java.lang.IllegalStateException: javax.websocket.server.ServerContainer not available
  6. 【转】NSBundle的使用,注意mainBundle和Custom Bundle的区别
  7. @Param注解在dao层的使用
  8. js中异步方案比较完整版(callback,promise,generator,async)
  9. 《毛毛虫组》【Alpha】Scrum meeting 4
  10. 瀑布流封装(仿写UITableView)