浅谈队列:https://www.cnblogs.com/AKMer/p/10314965.html

题目传送门:https://lydsy.com/JudgeOnline/problem.php?id=3403

直接双端队列模拟即可。

时间复杂度:\(O(S)\)

空间复杂度:\(O(S)\)

代码如下:

#include <cstdio>
using namespace std; const int maxn=1e5+5; char s1[5],s2[5];
int list[maxn<<1];
int n,head,tail,cnt; int read() {
int x=0,f=1;char ch=getchar();
for(;ch<'0'||ch>'9';ch=getchar())if(ch=='-')f=-1;
for(;ch>='0'&&ch<='9';ch=getchar())x=x*10+ch-'0';
return x*f;
} int main() {
n=read();
head=tail=maxn;
while(n--) {
scanf("%s%s",s1+1,s2+1);
if(s1[1]=='A') {
if(s2[1]=='L')list[--head]=++cnt;
else list[tail++]=++cnt;
}
else {
int k=read();
if(s2[1]=='L')while(k--)head++;
else while(k--)tail--;
}
}
for(int i=head;i<tail;i++)
printf("%d\n",list[i]);
return 0;
}

最新文章

  1. WCF 定制自己的签名验证逻辑
  2. C# Process执行bat
  3. Windows server 2008R2部署服务批量安装Windows7教程
  4. 【PAT】1020. Tree Traversals (25)
  5. Python 第十二篇:HTML基础
  6. OTG驱动分析(二)
  7. win7电脑关机时间长怎么办
  8. iOS 本地视频和网络视频流播放
  9. 第二次作业:APP案例分析
  10. Spring cloud Greenwich Eureka
  11. vue-element-ui之弹窗重置
  12. 乐观锁vs悲观锁, 集群vs分布式 , 微服务, 幂等性
  13. 【hdu2000】ASCII码排序
  14. GFS浅析
  15. testng报告-extentsReports使用-klov
  16. C# 百度TTS,文本转语音,RestAPI之Get请求
  17. grid - 重复网格轨道
  18. vb.net連接Oracle数据库
  19. 第十七篇:IO复用之select实现
  20. ELK之收集tomcat访问日志

热门文章

  1. Android摄像头测量尺(Advanced Ruler Pro)使用方法
  2. gstreamer交叉编译
  3. R和Python小数的保留
  4. winter 2018 02 01 关于模运算的一道题
  5. Android系统--灯光系统驱动编写
  6. GCC编译器入门[转载]
  7. 最短路径Dijkstra模板
  8. C#中的转义字符verbatim string
  9. ZooKeeper学习第八期---ZooKeeper伸缩性
  10. tensorflow笔记:多层CNN代码分析