c++ list使用

 #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <time.h>
#include <string>
#include <set>
#include <map>
#include <list>
#include <ext/rope>
#include <stack>
#include <queue>
#include <vector>
#include <bitset>
#include <algorithm>
#include <iostream>
using namespace std;
#define ll long long
#define minv 1e-6
#define inf 1e9
#define pi 3.1415926536
#define E 2.7182818284
const ll mod=1e9+;//
const int maxn=;
using namespace __gnu_cxx; char ch; void read(int &x){
ch = getchar();x = ;
for (; ch < '' || ch > ''; ch = getchar());
for (; ch >='' && ch <= ''; ch = getchar()) x = x * + ch - '';
} list<int>f[maxn]; int main()
{
int n,q,mode,u,w,val,v,i;
while (~scanf("%d%d",&n,&q))
{
for (i=;i<=n;i++)
f[i].clear();
while (q--)
{
read(mode);
if (mode==)
{
read(u),read(w),read(val);
if (w)
f[u].push_back(val);
else
f[u].push_front(val);
}
//
else if (mode==)
{
read(u),read(w);
if (f[u].empty())
printf("-1\n");
else
{
if (w)
{
printf("%d\n",f[u].back());
f[u].pop_back();
}
else
{
printf("%d\n",f[u].front());
f[u].pop_front();
}
}
}
//
else
{
read(u),read(v),read(w);
if (w)
reverse(f[v].begin(),f[v].end());
f[u].splice(f[u].end(),f[v]); //or // if (w)
// f[u].insert(f[u].end(),f[v].rbegin(),f[v].rend());
// else
// f[u].insert(f[u].end(),f[v].begin(),f[v].end());
f[v].clear();
}
}
}
return ;
}
/*
2 30
1 1 0 123
1 1 0 1234
1 2 1 2333
1 2 1 23333
1 2 1 233333
1 2 1 2333333
1 2 1 23333333
2 2 0
2 2 1
3 1 2 1
2 1 1
2 1 1
2 1 1
2 1 1
2 1 1
2 1 1
3 1 5 0
1 5 1 1
2 5 1
*/

用rope超时了

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <time.h>
#include <string>
#include <set>
#include <map>
#include <list>
#include <ext/rope>
#include <stack>
#include <queue>
#include <vector>
#include <bitset>
#include <algorithm>
#include <iostream>
using namespace std;
#define ll long long
#define minv 1e-6
#define inf 1e9
#define pi 3.1415926536
#define E 2.7182818284
const ll mod=1e9+;//
const int maxn=;
using namespace __gnu_cxx; void read(int &x){
char ch = getchar();x = ;
for (; ch < '' || ch > ''; ch = getchar());
for (; ch >='' && ch <= ''; ch = getchar()) x = x * + ch - '';
} rope<int>f[maxn],ff[maxn]; int main()
{
int n,q,mode,u,w,val,v,i;
while (~scanf("%d%d",&n,&q))
{
for (i=;i<=n;i++)
f[i].clear(),ff[i].clear();
while (q--)
{
read(mode);
if (mode==)
{
read(u),read(w),read(val);
if (w==)
{
f[u].push_back(val);
ff[u].insert(,val);
}
else
{
f[u].insert(,val);
ff[u].push_back(val);
}
}
else if (mode==)
{
read(u),read(w);
if (f[u].empty())
printf("-1\n");
else
{
if (w==)
{
printf("%d\n",f[u].at(f[u].size()-));
f[u].erase(f[u].size()-,);
ff[u].erase(,);
}
else
{
printf("%d\n",f[u].at());
f[u].erase(,);
ff[u].erase(f[u].size()-,);
}
}
}
else
{
read(u),read(v),read(w);
if (w==)
{
f[u].append(f[v]);
ff[u]=ff[v]+ff[u];
f[v].clear();
ff[v].clear();
}
else
{
f[u].append(ff[v]);
ff[u]=f[v]+ff[u];
f[v].clear();
ff[v].clear();
}
}
}
}
return ;
}

2018 “百度之星”程序设计大赛 - 初赛(A)度度熊学队列 list rope的更多相关文章

  1. HDU6383 2018 “百度之星”程序设计大赛 - 初赛(B) 1004-p1m2 (二分)

    原题地址 p1m2 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total ...

  2. HDU6380 2018 “百度之星”程序设计大赛 - 初赛(B) A-degree (无环图=树)

    原题地址 degree Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Tot ...

  3. 2018 “百度之星”程序设计大赛 - 初赛(A)

    第二题还算手稳+手快?最后勉强挤进前五百(期间看着自己从两百多掉到494名) 1001  度度熊拼三角    (hdoj 6374) 链接:http://acm.hdu.edu.cn/showprob ...

  4. 【2018 “百度之星”程序设计大赛 - 初赛(B)-1004】p1m2(迷之二分)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6383 题目就是让你求一个整数数组,在进行任意元素 + 1. - 2 操作后,请问在所有可能达到的稳定数 ...

  5. 【2018 “百度之星”程序设计大赛 - 初赛(B)- 1001】degree

    Problem Description 度度熊最近似乎在研究图论.给定一个有 N 个点 (vertex) 以及 M 条边 (edge) 的无向简单图 (undirected simple graph) ...

  6. 2018 “百度之星”程序设计大赛 - 初赛(B)

    degree  Accepts: 1581  Submissions: 3494  Time Limit: 2000/1000 MS (Java/Others)  Memory Limit: 1310 ...

  7. 2017"百度之星"程序设计大赛 - 资格赛 1002 度度熊的王国战略

    全局最小割 Stoer-Wagner (SW算法)优化 优化吃藕了,感谢放宽时限,感谢平板电视 (pb_ds) #include <iostream> #include <cstdi ...

  8. HDU 6118 度度熊的交易计划 【最小费用最大流】 (2017"百度之星"程序设计大赛 - 初赛(B))

    度度熊的交易计划 Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total S ...

  9. HDU 6119 小小粉丝度度熊 【预处理+尺取法】(2017"百度之星"程序设计大赛 - 初赛(B))

    小小粉丝度度熊 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Sub ...

随机推荐

  1. node http模块搭建简单的服务和客户端

    node-http Node.js提供了http模块,用于搭建HTTP服务端和客户端. 创建Web服务器 server.js /** * node-http 服务端 */ let http = req ...

  2. 1.centos6.8安装docker

    简介环境安装依赖安装步骤1.删除旧版本的docker2.安装docker2.1 yum安装docker2.2 tar安装2.3 在线脚本事实证明以上的安装方式都行不通 参考文档:https://doc ...

  3. 作业1-MathExam

    MathExam 一.预估与实际 PSP2.1 Personal Software Process Stages 预估耗时(分钟) 实际耗时(分钟) Planning 计划 10 30 • Estim ...

  4. C++:模板——函数模板1

    一.为什么使用函数模板 假设我们在程序中需要比较两个变量的大小,但变量的类型可能是int.float或者double,此时为了满足程序的要求我们可能会在程序中编写多个函数,如: //比较两个int型变 ...

  5. C# Linq找不到行或已更改

    前段时间工作中的一个新需求,有机会用到了Linq to SQL.使用后的第一感觉,就是方便很多,也为整个项目节约了一大把的开发时间,甚至代码量也少了很多.不过在程序的实际运行中,始终会遇到一些莫名其妙 ...

  6. 人and绩效and职业道德

    人行走在这个世界上 避免不了的是各种悲哀 人就像是一个茶几 上面放满了各种杯具 而要做的是要么把杯具打碎了咽下去,要么被杯具打晕 本布衣 躬耕于南阳 不求闻达于诸侯 每个人都可以选择自己的生活方式 或 ...

  7. 45度炸队Alpha冲刺博客集

    博客集如下: Alpha冲刺Day1:第一天冲刺记录 Alpha冲刺Day2:第二天冲刺记录 Alpha冲刺Day3:第三天冲刺记录 Alpha冲刺Day4:第四天冲刺记录 Alpha冲刺Day5:第 ...

  8. 信安实践——自建CA证书搭建https服务器

    1.理论知识 https简介 HTTPS(全称:Hyper Text Transfer Protocol over Secure Socket Layer),是以安全为目标的HTTP通道,简单讲是HT ...

  9. 1105 C程序的推导过程

  10. [2017BUAA软工]第2次个人作业

    软工第2次个人作业--代码复审 一.代码复审Check List 1.概要部分 代码能符合需求和规格说明么? 能正确处理题目要求,代码能符合需求和规格. 代码设计是否有周全的考虑? 能正确生成和解出数 ...