Open Judge 3339 List
3339:List
- 总时间限制:
- 4000ms
- 内存限制:
- 65536kB
- 描述
-
写一个程序完成以下命令:
new id ——新建一个指定编号为id的序列(id<10000)
add id num——向编号为id的序列加入整数num
merge id1 id2——合并序列id1和id2中的数,并将id2清空
unique id——去掉序列id中重复的元素
out id ——从小到大输出编号为id的序列中的元素,以空格隔开 - 输入
- 第一行一个数n,表示有多少个命令( n<=200000)。以后n行每行一个命令。
- 输出
- 按题目要求输出。
- 样例输入
-
16
new 1
new 2
add 1 1
add 1 2
add 1 3
add 2 1
add 2 2
add 2 3
add 2 4
out 1
out 2
merge 1 2
out 1
out 2
unique 1
out 1 - 样例输出
-
1 2 3
1 2 3 4
1 1 2 2 3 3 4 1 2 3 4#include <cstdio>
#include <iostream>
#include <cstring>
#include <list>
#include <map>
using namespace std; map<int,list<int> > m; int n,x,y;
char op[];
int main(){
scanf("%d",&n);
while(n--){
scanf("%s",op);
if(strcmp(op,"new")==){
scanf("%d",&x);
m.insert(map<int,list<int> >::value_type(x,list<int>()));
}
if(strcmp(op,"add")==){
scanf("%d%d",&x,&y);
m[x].push_back(y);
}
if(strcmp(op,"merge")==){
scanf("%d%d",&x,&y);
m[x].merge(m[y]);
//m[y].clear();
}
if(strcmp(op,"unique")==){
scanf("%d",&x);
m[x].sort();
m[x].unique();
}
if(strcmp(op,"out")==){
scanf("%d",&x);
m[x].sort();
list<int>::iterator it;
for(it=m[x].begin();it!=m[x].end();it++){
printf("%d ",*it);
}
printf("\n");
}
}
}竟然还有list这STL,长见识了真是~~唉~~
Open Judge 3339 List的更多相关文章
- Gym 101102C---Bored Judge(区间最大值)
题目链接 http://codeforces.com/gym/101102/problem/C problem description Judge Bahosain was bored at ACM ...
- BZOJ 3339 & 莫队+"所谓的暴力"
题意: 给一段数字序列,求一段区间内未出现的最小自然数. SOL: 框架显然用莫队.因为它兹瓷离线. 然而在统计上我打了线段树...用&维护的结点...400w的线段树...然后二分查找... ...
- NOJ 1074 Hey Judge(DFS回溯)
Problem 1074: Hey Judge Time Limits: 1000 MS Memory Limits: 65536 KB 64-bit interger IO format: ...
- 【教程】如何正确的写一个Lemon/Cena的SPJ(special judge)
转自:http://www.cnblogs.com/chouti/p/5752819.html Special Judge:当正确的输出结果不唯一的时候需要的自定义校验器 首先有个框架 #includ ...
- 九度 Online Judge 之《剑指 Offer》一书相关题目解答
前段时间准备华为机试,正好之前看了一遍<剑指 Offer>,就在九度 Online Judge 上刷了书中的题目,使用的语言为 C++:只有3题没做,其他的都做了. 正如 Linus To ...
- hdu 3339 In Action 背包+flyod
In Action Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=333 ...
- UVa Online Judge 工具網站
UVa Online Judge 工具網站 UVa中译题uHuntAlgorithmist Lucky貓的ACM園地,Lucky貓的 ACM 中譯題目 Mirror UVa Online Judg ...
- [swustoj 1021] Submissions of online judge
Submissions of online judge(1021) 问题描述 An online judge is a system to test programs in programming c ...
- Bzoj 3339: Rmq Problem && Bzoj 3585: mex 莫队,树状数组,二分
3339: Rmq Problem Time Limit: 20 Sec Memory Limit: 128 MBSubmit: 833 Solved: 397[Submit][Status][D ...
随机推荐
- empty 和 isset的区别和联系
empty 和 isset的区别和联系 要说它们的联系,其共同点就是empty()和isset()都是变量处理函数,作用是判断变量是否已经配置,正是由于它们在处理变量过程中有很大的相似性,才导致对它们 ...
- AJPFX浅谈Java 性能优化之字符串过滤实战
★一个简单的需求 首先描述一下需求:给定一个 String 对象,过滤掉除了数字(字符'0'到'9')以外的其它字符.要求时间开销尽可能小.过滤函数的原型如下: String filter(Strin ...
- JavaWeb ,EL,
WEB 概述: java web 是用java 技术来解决相关web 互联网领域的技术总和 . web 可分为 web服务器和web客户端(浏览器) web 的资源分类: 静态资源: HTM ...
- Java GUI 基础组件
1.JLabel 标签 构造函数: JLabel() JLabel(String text) JLabel(String text,int align) //第二个参数设置文本的对齐方式,常 ...
- QTabelwidget 添加复选框
QString sceneName = QString("%1(%2)").arg(sisList[i].sceneName).arg(sisList[i].sceneNo); Q ...
- 7-Java-C(四平方和)
题目描述: 四平方和定理,又称为拉格朗日定理: 每个正整数都可以表示为至多4个正整数的平方和. 如果把0包括进去,就正好可以表示为4个数的平方和. 比如: 5 = 0^2 + 0^2 + 1^2 + ...
- python_使用qrcode生成二维码
1.功能 使用qrcode生成二维码 2.代码 #生成二维码: import qrcode #根据url生成二维码 def qrcodeWithUrl(url): img = qrcode.make( ...
- this.$Message.success('提示信息') 少写了一个c 导致报错
this.$Message.success('提示信息') 少写了一个c 导致报错 而且 $Message 输出还没显示,导致我以为是没有 $Message 对象了,其实全局对象直接调用即可
- vscode 打开新文件不替换旧文件
设置 "workbench.editor.enablePreview": false
- 查看cuda版本和cudann
nvcc -V 没有找到直接查询cudann版本的命令,但发现cudann装在 /usr/local/cuda/lib64/目录下,libcudnn.so就是相应版本