ZOJ - 4016

vector又T又M

list是以链表的方式存储的 是一个双向链表

元素转移操作中,不能一个个遍历加入到s中,list独有的splic函数可以在常数时间内实现合并(并删除源list)

splice()有三种调用形式:
第一种: list1.splice(it1, list2).将list2中的所有元素拷贝到list1中。在list1中的起始位置是it1.复制结束后,list2将为空。

第二种调用形式:
list1.splice(it1, list2, it2)
这个功能是将list2中的元素,从it2开始,剪切到list1的it1起始的地方。

第三种调用形式:
list1.splice(it1, list2, it2begin, it2end)

#include <iostream>
#include <cstdio>
#include <sstream>
#include <cstring>
#include <map>
#include <cctype>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <algorithm>
#include <cmath>
#include <bitset>
#define rap(i, a, n) for(int i=a; i<=n; i++)
#define rep(i, a, n) for(int i=a; i<n; i++)
#define lap(i, a, n) for(int i=n; i>=a; i--)
#define lep(i, a, n) for(int i=n; i>a; i--)
#define rd(a) scanf("%d", &a)
#define rlld(a) scanf("%lld", &a)
#define rc(a) scanf("%c", &a)
#define rs(a) scanf("%s", a)
#define rb(a) scanf("%lf", &a)
#define rf(a) scanf("%f", &a)
#define pd(a) printf("%d\n", a)
#define plld(a) printf("%lld\n", a)
#define pc(a) printf("%c\n", a)
#define ps(a) printf("%s\n", a)
#define MOD 2018
#define LL long long
#define ULL unsigned long long
#define Pair pair<int, int>
#define mem(a, b) memset(a, b, sizeof(a))
#define _ ios_base::sync_with_stdio(0),cin.tie(0)
//freopen("1.txt", "r", stdin);
using namespace std;
const int maxn = , INF = 0x7fffffff; list<int> G[maxn]; int main()
{
int T;
rd(T);
while(T--)
{
int n, q;
rd(n), rd(q);
for(int i = ; i <= n; i++) G[i].clear();
for(int i = ; i < q; i++)
{
int id, v, s, t;
rd(id);
if(id == )
{
rd(s), rd(v);
G[s].push_back(v);
}
else if(id == )
{
rd(s);
if(G[s].empty())
{
printf("EMPTY\n");
continue;
}
printf("%d\n", G[s].back());
G[s].pop_back();
}
else
{
rd(s), rd(t);
// for(list<int>::iterator it = G[t].begin(); it != G[t].end(); it++)
// G[s].push_back(*it);
// G[t].clear();
G[s].splice(G[s].end(), G[t]);
} } } return ;
}

Mergeable Stack ZOJ - 4016(list)的更多相关文章

  1. Mergeable Stack(链表实现栈)

    C - Mergeable Stack ZOJ - 4016 一开始用stl中内置的栈来写,其中第三个操作,我先复制到一个数组,再将其倒给另一个栈 这个方法有两个错误的地方: 1.栈在内存很大需要扩容 ...

  2. ZOJ 4016 Mergeable Stack(利用list模拟多个栈的合并,STL的应用,splice函数!!!)

    Mergeable Stack Time Limit: 2 Seconds      Memory Limit: 65536 KB Given initially empty stacks, ther ...

  3. ZOJ 4016 Mergeable Stack(栈的数组实现)

    Mergeable Stack Time Limit: 2 Seconds      Memory Limit: 65536 KB Given  initially empty stacks, the ...

  4. ZOJ 4016 Mergeable Stack 链表

    Mergeable Stack Time Limit: 2 Seconds      Memory Limit: 65536 KB Given  initially empty stacks, the ...

  5. C Mergeable Stack(list超好用)

    ZOJ  4016 list用法https://www.cnblogs.com/LLLAIH/p/10673068.html 一开始用普通的栈做,超内存,链表模拟栈也没写出来orz.补题发现list超 ...

  6. ZOJ - 4016 Mergeable Stack 【LIST】

    题目链接 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=4016 题意 模拟栈的三种操作 第一种 push 将指定元素压入指 ...

  7. ZOJ - 4016 Mergeable Stack (STL 双向链表)

    [传送门]http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=4016 [题目大意]初始有n个空栈,现在有如下三种操作: (1) ...

  8. ZOJ 4016 Mergeable Stack(from The 18th Zhejiang University Programming Contest Sponsored by TuSimple)

    模拟题,用链表来进行模拟 # include <stdio.h> # include <stdlib.h> typedef struct node { int num; str ...

  9. [ZOJ 4016] Mergable Stack

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=4016 直接用栈爆内存,看网上大神用数组实现的,构思巧妙,学习了! ...

随机推荐

  1. c# String ,String[] 和 List<String>之间的转换

    C#对字符串进行处理时,经常需要进行String,String[]和List<String>之间的转换 本文分析一下它们的差异和转换 一. 1. String > String[] ...

  2. SqlSugar ORM 入门篇2 【查询】 让我们实现零SQL

    SqlSugar在查询的功能是非常强大的,多表查询.分页查询 . 一对一查询.二级缓存.一对多查.WhenCase等复杂函数.Mapper功能.和拉姆达自定义扩展等,用好了是可以做到真正零SQL的一款 ...

  3. Java SimpleDateFormat处理日期与字符串的转换

    1.为什么要使用SimpleDateFormat? 在Java中,如果我们想获取当前时间,一般会使用Date类的无参构造函数,如下所示,我们获取到当前时间并输出: import java.util.D ...

  4. 迭代器模式 Iterator 行为型 设计模式(二十)

    迭代器模式(Iterator)   走遍天下,世界那么大,我想去看看   在计算机中,Iterator意为迭代器,迭代有重复的含义,在程序中,更有“遍历”的含义 如果给定一个数组,我们可以通过for循 ...

  5. php 获取URL 各部分参数

    URL处理几个关键的函数parse_url.parse_str与http_build_query parse_url() 该函数可以解析 URL,返回其组成部分.它的用法如下: array parse ...

  6. [C#学习笔记1]用csc.exe和记事本写一个C#应用程序

    csc.exe是C#的命令行编译器(CSharpCompiler),可以编译C#源程序成可执行程序.它与Visual Studio等IDE(Integrated Development Environ ...

  7. 【English】四、Y结尾名词变复数

    一.辅音字母+y结尾的名词,将y改变为i,再加-es. 读音变化:加读[z]. 例: candy→candies; daisy→daisies; fairy→fairies; lady→ladies; ...

  8. Github入门详情教程

    前言 之前我写了一篇文章<一篇文章了解Github和Git教程>还延伸了几篇阅读,对大部分小白很有用,那么我继续普及下Github页面及其概念. 定义 GitHub 是一个网站,一个面向开 ...

  9. golang 调用windows API 中文的处理

    Go语言发展势头很猛,其实缺点也很多,好在有广大爱好者提供了无数的库,把优点表现得太好了,搞得什么都是拿来就使用,基本完全不理会指针,性能还不错. 最近在windows下使用遇到一个中文的问题,首先要 ...

  10. 【技术说明】iOS10来了,AppCan已全面适配!

    IPhone 7出了,你的肾还好吗?别紧张,不买肾7,同样可以体验最新的iOS10! AppCan对引擎.插件.编译系统等都进行了重要升级,让你的APP轻松适配iOS10!具体如何,请往下看! 引擎 ...