用stl的list即可,注意。。。代码的简洁性(被debug伤痛)注意合并时可以手动pop,或者用splice进行合并,不能用merge!!!merge合并是自带排序!!!

#include<bits/stdc++.h>
#include<deque>
using namespace std;
inline int read(){
char c=getchar();int x=,f=;
while(c<''||c>''){if(c=='-')f=-;c=getchar();}
while(c>=''&&c<=''){x=x*+c-'';c=getchar();}
return x*f;
}
std::list<int>::iterator it;
int main()
{
int n,q,cmd;
int u,w,val,s,v;
int ans;
while(~scanf("%d%d",&n,&q))
{
list<int>que[];
while(q--)
{
cmd=read();
if(cmd==)
{
u=read();w=read();val=read();
if (w)
{
que[u].push_back(val);
}
else
{
que[u].push_front(val);
}
}
else if (cmd==)
{
u=read();
w=read();
if (w)
{
if (que[u].empty())
{
printf("-1\n");
continue;
} ans=que[u].back();
printf("%d\n",ans);
que[u].pop_back();
}
else
{
if (que[u].empty())
{
printf("-1\n");
continue;
}
ans=que[u].front();
printf("%d\n",ans);
que[u].pop_front();
}
}
else {
u=read();
v=read();
w=read();
int temp;
if (w==){
it=que[u].end();
que[u].splice(it,que[u]);
}else {
it=que[u].end();
que[v].reverse();
que[u].splice(it,que[v]);
}
}
}
}
return ;
}

最新文章

  1. Linux2.6内核协议栈系列--TCP协议1.发送
  2. canvas画圆百分比显示
  3. 用Python写一个简单的Web框架
  4. JAVA代码发送邮件示例和解释
  5. ubuntu下非本账户的.profile文件的修改
  6. 使用nginx lua实现网站统计中的数据收集
  7. SendKeys:基本使用
  8. Android Studio如何添加override
  9. mysqldump: Got error: 1556: You can&#39;t use locks with log tables. when using LOCK TABLES
  10. Linux命令-sudo
  11. 正式学习React(一) 开始学习之前必读
  12. hdu 4031 Attack 线段树
  13. [置顶] 初识window.location.search
  14. 强大的oracle分析函数
  15. 直播框架ijkplayer
  16. matlab: Attempt to execute SCRIPT *** as a function 错误
  17. Unix环境高级编程(六)进程控制
  18. python2.7中关于编码,json格式的中文输出显示
  19. PHP权限控制(转)
  20. range开始节点和结束节点

热门文章

  1. 环境搭建-----IntelliJ idea之resin配置
  2. ajaxForm和ajaxSubmit 粘贴就可用
  3. MySQL备份及数据恢复
  4. PCB
  5. 如何在一台机器上部署多个tomcat
  6. 在 Linux 上安装 Oracle 数据库 11g
  7. P1004 方格取数-洛谷luogu-dp动态规划
  8. js将有父子关系的数据转换成树形结构数据
  9. nohup: failed to run command `java&#39;: No such file or directory
  10. Objective-C weak深入理解