c++ list使用

  1. #include <cstdio>
  2. #include <cstdlib>
  3. #include <cmath>
  4. #include <cstring>
  5. #include <time.h>
  6. #include <string>
  7. #include <set>
  8. #include <map>
  9. #include <list>
  10. #include <ext/rope>
  11. #include <stack>
  12. #include <queue>
  13. #include <vector>
  14. #include <bitset>
  15. #include <algorithm>
  16. #include <iostream>
  17. using namespace std;
  18. #define ll long long
  19. #define minv 1e-6
  20. #define inf 1e9
  21. #define pi 3.1415926536
  22. #define E 2.7182818284
  23. const ll mod=1e9+;//
  24. const int maxn=;
  25. using namespace __gnu_cxx;
  26.  
  27. char ch;
  28.  
  29. void read(int &x){
  30. ch = getchar();x = ;
  31. for (; ch < '' || ch > ''; ch = getchar());
  32. for (; ch >='' && ch <= ''; ch = getchar()) x = x * + ch - '';
  33. }
  34.  
  35. list<int>f[maxn];
  36.  
  37. int main()
  38. {
  39. int n,q,mode,u,w,val,v,i;
  40. while (~scanf("%d%d",&n,&q))
  41. {
  42. for (i=;i<=n;i++)
  43. f[i].clear();
  44. while (q--)
  45. {
  46. read(mode);
  47. if (mode==)
  48. {
  49. read(u),read(w),read(val);
  50. if (w)
  51. f[u].push_back(val);
  52. else
  53. f[u].push_front(val);
  54. }
  55. //
  56. else if (mode==)
  57. {
  58. read(u),read(w);
  59. if (f[u].empty())
  60. printf("-1\n");
  61. else
  62. {
  63. if (w)
  64. {
  65. printf("%d\n",f[u].back());
  66. f[u].pop_back();
  67. }
  68. else
  69. {
  70. printf("%d\n",f[u].front());
  71. f[u].pop_front();
  72. }
  73. }
  74. }
  75. //
  76. else
  77. {
  78. read(u),read(v),read(w);
  79. if (w)
  80. reverse(f[v].begin(),f[v].end());
  81. f[u].splice(f[u].end(),f[v]);
  82.  
  83. //or
  84.  
  85. // if (w)
  86. // f[u].insert(f[u].end(),f[v].rbegin(),f[v].rend());
  87. // else
  88. // f[u].insert(f[u].end(),f[v].begin(),f[v].end());
  89. f[v].clear();
  90. }
  91. }
  92. }
  93. return ;
  94. }
  95. /*
  96. 2 30
  97. 1 1 0 123
  98. 1 1 0 1234
  99. 1 2 1 2333
  100. 1 2 1 23333
  101. 1 2 1 233333
  102. 1 2 1 2333333
  103. 1 2 1 23333333
  104. 2 2 0
  105. 2 2 1
  106. 3 1 2 1
  107. 2 1 1
  108. 2 1 1
  109. 2 1 1
  110. 2 1 1
  111. 2 1 1
  112. 2 1 1
  113. 3 1 5 0
  114. 1 5 1 1
  115. 2 5 1
  116. */

用rope超时了

  1. #include <cstdio>
  2. #include <cstdlib>
  3. #include <cmath>
  4. #include <cstring>
  5. #include <time.h>
  6. #include <string>
  7. #include <set>
  8. #include <map>
  9. #include <list>
  10. #include <ext/rope>
  11. #include <stack>
  12. #include <queue>
  13. #include <vector>
  14. #include <bitset>
  15. #include <algorithm>
  16. #include <iostream>
  17. using namespace std;
  18. #define ll long long
  19. #define minv 1e-6
  20. #define inf 1e9
  21. #define pi 3.1415926536
  22. #define E 2.7182818284
  23. const ll mod=1e9+;//
  24. const int maxn=;
  25. using namespace __gnu_cxx;
  26.  
  27. void read(int &x){
  28. char ch = getchar();x = ;
  29. for (; ch < '' || ch > ''; ch = getchar());
  30. for (; ch >='' && ch <= ''; ch = getchar()) x = x * + ch - '';
  31. }
  32.  
  33. rope<int>f[maxn],ff[maxn];
  34.  
  35. int main()
  36. {
  37. int n,q,mode,u,w,val,v,i;
  38. while (~scanf("%d%d",&n,&q))
  39. {
  40. for (i=;i<=n;i++)
  41. f[i].clear(),ff[i].clear();
  42. while (q--)
  43. {
  44. read(mode);
  45. if (mode==)
  46. {
  47. read(u),read(w),read(val);
  48. if (w==)
  49. {
  50. f[u].push_back(val);
  51. ff[u].insert(,val);
  52. }
  53. else
  54. {
  55. f[u].insert(,val);
  56. ff[u].push_back(val);
  57. }
  58. }
  59. else if (mode==)
  60. {
  61. read(u),read(w);
  62. if (f[u].empty())
  63. printf("-1\n");
  64. else
  65. {
  66. if (w==)
  67. {
  68. printf("%d\n",f[u].at(f[u].size()-));
  69. f[u].erase(f[u].size()-,);
  70. ff[u].erase(,);
  71. }
  72. else
  73. {
  74. printf("%d\n",f[u].at());
  75. f[u].erase(,);
  76. ff[u].erase(f[u].size()-,);
  77. }
  78. }
  79. }
  80. else
  81. {
  82. read(u),read(v),read(w);
  83. if (w==)
  84. {
  85. f[u].append(f[v]);
  86. ff[u]=ff[v]+ff[u];
  87. f[v].clear();
  88. ff[v].clear();
  89. }
  90. else
  91. {
  92. f[u].append(ff[v]);
  93. ff[u]=f[v]+ff[u];
  94. f[v].clear();
  95. ff[v].clear();
  96. }
  97. }
  98. }
  99. }
  100. return ;
  101. }

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. 搬运_maven打包

    参考文章 利用Maven插件将依赖包.jar/war包及配置文件输出到指定目录 <build> <plugins> <plugin> <groupId> ...

  2. Qt tableWidget 空单元格 获取选中行行号

    bool focus = tableWidget->isItemSelected(tableWidget->currentItem()); // 判断是否选中一行 Int row1 = t ...

  3. lscpi命令详解

    基础命令学习目录 lspci是一个用来查看系统中所有PCI总线以及连接到该总线上的设备的工具. 命令格式为 lspci -参数 (不加参数显示所有硬件设备) 至于有哪些参数及其详细用法可以看下这篇博客 ...

  4. python清空列表的方法

    1.大数据量的list,要进行局部元素删除,尽量避免用del随机删除,非常影响性能,如果删除量很大,不如直接新建list,然后用下面的方法释放清空旧list. 2.对于一般性数据量超大的list,快速 ...

  5. 最详细的springmvc-mybatis教程

    链接:http://blog.csdn.net/qq598535550/article/details/51703190

  6. CF 1100C NN and the Optical Illusion(数学)

    NN is an experienced internet user and that means he spends a lot of time on the social media. Once ...

  7. Windows下Visual Studio2017之AI环境搭建

    本博客主要包含以下3点: AI简介及本博客主要目的 环境介绍及安装原因 搭建环境及检验是否安装成功 离线模型的训练 时间分配:   时间 时长(分钟) 收集资料+写博客 6.12 11:28-12:2 ...

  8. Teamproject Week7 --Scrum Meeting #1 2014.10.28

    这是团队的第一次会议,具体议题如下: 1)我们明确了团队成员的职责所需: PM职责:根据项目范围.质量.时间与成本的综合因素的考虑,进行项目的总体规划与阶段计划.  控制项目组各成员的工作进度,即时了 ...

  9. 实验五 — — Java网络编程及安全

    java的第五个实验——Java网络编程及安全 北京电子科技学院 实     验    报     告 课程:Java程序设计 班级:1352 姓名:林涵锦 学号:20135213    成绩:    ...

  10. Beta版本发布140字评论

    1.飞天小女警组: 礼物挑选工具:系统界面十分新颖,相比于前阶段,增加了账号登陆的功能,并且还根据不同的价位区间添加了礼物的图片,并根据礼物的受欢迎程度添加了top10的功能,并且增加了关于本网站的问 ...