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