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. 线程_synchronized_volatile_ReentranLock

    线程:cpu同时执行多个任务 synchonized   代码块,对象,类 同步方法和非同步方法可以同时执行同步方法可以调用同步方法(重入)脏读:之同步写,不同步读死锁的demo  一个线程先对A加锁 ...

  2. uiimageview 的 animation 动画

    NSMutableArray *meiArr = [NSMutableArray arrayWithCapacity:4]; for (int i = 0; i < 4; i++) { NSSt ...

  3. 模块-Memcached、Redis

    目录 Mecache 安装 使用 Redis 安装 Python操作Redis 操作模式 连接池 操作 String Hash List Set sort set 其他常用操作 管道 发布订阅 sen ...

  4. 我现在对Git的认识

    由于时间关系,我还没能真正的了解什么是Git,只是大致的了解了一下,并且在网上查阅了资料,做了一些总结,以便进一步研读. Git是一款免费.开源的分布式版本控制系统,用于敏捷高效地处理任何或小或大的项 ...

  5. Leetcode题库——21.合并两个有序链表

    @author: ZZQ @software: PyCharm @file: mergeTwoLists.py @time: 2018/9/16 20:49 要求:将两个有序链表合并为一个新的有序链表 ...

  6. 【动态规划】POJ-2229

    一.题目 Description Farmer John commanded his cows to search for different sets of numbers that sum to ...

  7. 树莓派与Arduino Leonardo使用NRF24L01无线模块通信之基于RF24库 (三) 全双工通信

    设计思路 Arduino Leonardo初始化为发送模式,发送完成后,立即切换为接收模式,不停的监听,收到数据后立即切换为发送模式,若超过一定时间还为接收到数据,则切换为发送模式. 树莓派初始化为接 ...

  8. MapReduce编程之Semi Join多种应用场景与使用

    Map Join 实现方式一 ● 使用场景:一个大表(整张表内存放不下,但表中的key内存放得下),一个超大表 ● 实现方式:分布式缓存 ● 用法: SemiJoin就是所谓的半连接,其实仔细一看就是 ...

  9. iOS App之间常用的五种通信方式及适用场景总结

    iOS系统是相对封闭的系统,App各自在各自的沙盒(sandbox)中运行,每个App都只能读取iPhone上iOS系统为该应用程序程序创建的文件夹AppData下的内容,不能随意跨越自己的沙盒去访问 ...

  10. Beta阶段——第二篇 Scrum 冲刺博客

    i. 提供当天站立式会议照片一张: ii. 每个人的工作 (有work item 的ID) (1) 昨天已完成的工作: 账单收支分明,剩余舍费关联成功 (2) 今天计划完成的工作: 账单删除功能,排序 ...