Ivan comes again!

Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^

题目描述

The Fairy Ivan gave Saya three problems to solve (Problem F). After Saya finished the first problem (Problem H), here comes the second.
This is the enhanced version of Problem H.
There is a large matrix whose row and column are less than or equal to 1000000000. And there are three operations for the matrix:
1)add: Mark an element in the matrix. The element wasn’t marked before it is marked.
2)remove: Delete an element’s mark. The element was marked before the element’s mark is deleted.
3)find: Show an element’s row and column, and return a marked element’s row and column, where the marked element’s row and column are larger than the showed element’s row and column respectively. If there are multiple solutions, return the element whose row is the smallest; and if there are still multiple solutions, return the element whose column is the smallest. If there is no solution, return -1.
Of course, Saya comes to you for help again.

输入

The input consists of several test cases.
The first line of input in each test case contains one integer N (0<N≤200000), which represents the number of operations.
Each of the next N lines containing an operation, as described above.
The last case is followed by a line containing one zero.

输出

For each case, print the case number (1, 2 …) first. Then, for each “find” operation, output the result. Your output format should imitate the sample output. Print a blank line after each test case.

示例输入

4
add 2 3
find 1 2
remove 2 3
find 1 2 0

示例输出

Case 1:
2 3
-1

提示

 

来源

 2010年山东省第一届ACM大学生程序设计竞赛

 
  STL模板库之set的使用
  这道题没有算法,纯粹是set的使用。
  因为要求的数组很大,开数组的话根本开不出来。
【set使用心得】
begin()  返回指向第一个元素的迭代器
ps:迭代器可以理解为“指针”,使用的使用和指针一样使用。
例如:
set <int> s;  //定义一个集合set
set <int>::iterator it; //定义一个set<int>的迭代器
it = s.begin();
cout<<*it<<endl; //输出迭代器指向的元素的值
或者:
set <pair<int,int>> s;
set <pair<int,int>>::iterator it;  //定义一个迭代器
it = s.begin();
cout<<it->first<<' '<<it->second<<endl;  //输出迭代器指向的元素的值

clear()   清除所有元素
count()   返回某个值元素的个数
empty()   如果集合为空,返回true(真)
end()    返回指向最后一个元素之后的迭代器,不是最后一个元素
equal_range()   返回集合中与给定值相等的上下限的两个迭代器
ps:某个值的[val)区间的两个值。>=val的第一个值作为下限,>val的第一个值作为上限
erase()   删除集合中的元素
ps:删除值为val的元素直接用s.erase(val);或者可以删除迭代器指向那个元素
find()    返回一个指向被查找到元素的迭代器
ps:注意返回的是一个迭代器
get_allocator() 返回集合的分配器
insert() 在集合中插入元素
ps:要插入某个元素,直接s.insert(val);即可
lower_bound()   返回指向大于(或等于)某值的第一个元素的迭代器
ps:返回>=val的第一个元素的迭代器
key_comp()     返回一个用于元素间值比较的函数
max_size()     返回集合能容纳的元素的最大限值
rbegin()  返回指向集合中最后一个元素的反向迭代器
rend()   返回指向集合中第一个元素的反向迭代器
size()   集合中元素的数目
swap()   交换两个集合变量
upper_bound()   返回大于某个值元素的迭代器
ps:返回>val的第一个元素的迭代器
value_comp()    返回一个用于比较元素间的值的函数

  这道题拿来熟悉STL很不错。

  代码
 #include <iostream>
#include <stdio.h>
#include <set>
#include <utility>
using namespace std;
int main()
{
int cnt,n;
for(cnt=;cin>>n;cnt++){
if(n==) break;
getchar();
int i;
char str[];
int a,b;
set < pair<int,int> > s;
set < pair<int,int> >::iterator it; //定义迭代器
cout<<"Case "<<cnt<<':'<<endl;
for(i=;i<=n;i++){
cin>>str>>a>>b;
switch(str[]){
case 'a':
s.insert(make_pair(a,b)); //像集合s中插入pair(a,b)
break;
case 'r':
s.erase(make_pair(a,b)); //将集合s中值为pair(a,b)的元素删掉
break;
case 'f':
it = s.upper_bound(make_pair(a,b)); //返回集合中大于pair(a,b)的第一个元素
for(;it!=s.end();it++) //找到第一个比pair(a,b)大的元素
if(it->first > a && it->second > b)
break;
if(it==s.end())
cout<<-<<endl;
else
cout<<it->first<<' '<<it->second<<endl;
break;
default:break;
}
}
cout<<endl;
}
return ;
}

Freecode : www.cnblogs.com/yym2013

sdut 2159:Ivan comes again!(第一届山东省省赛原题,STL之set使用)的更多相关文章

  1. sdut 2158:Hello World!(第一届山东省省赛原题,水题,穷举)

    Hello World! Time Limit: 1000MS Memory limit: 65536K 题目描述 We know that Ivan gives Saya three problem ...

  2. sdut 2152:Balloons(第一届山东省省赛原题,DFS搜索)

    Balloons Time Limit: 1000MS Memory limit: 65536K 题目描述 Both Saya and Kudo like balloons. One day, the ...

  3. sdut 2153:Clockwise(第一届山东省省赛原题,计算几何+DP)

    Clockwise Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 Saya have a long necklace with ...

  4. sdut 2154:Shopping(第一届山东省省赛原题,水题)

    Shopping Time Limit: 1000MS Memory limit: 65536K 题目描述 Saya and Kudo go shopping together.You can ass ...

  5. sdut 2165:Crack Mathmen(第二届山东省省赛原题,数论)

    Crack Mathmen Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述  Since mathmen take securit ...

  6. sdut 2162:The Android University ACM Team Selection Contest(第二届山东省省赛原题,模拟题)

    The Android University ACM Team Selection Contest Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里 ...

  7. sdut 2163:Identifiers(第二届山东省省赛原题,水题)

    Identifiers Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述  Identifier is an important c ...

  8. sdut 2603:Rescue The Princess(第四届山东省省赛原题,计算几何,向量旋转 + 向量交点)

    Rescue The Princess Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 Several days ago, a b ...

  9. sdut 2416:Fruit Ninja II(第三届山东省省赛原题,数学题)

    Fruit Ninja II Time Limit: 5000MS Memory limit: 65536K 题目描述 Have you ever played a popular game name ...

随机推荐

  1. BeanUtils的介绍使用

    BeanUtils工具 在实际的开发中我们经常需要将用户的录入的数据进行封装为对象,那么如果使用反射和内省技术就会变得吃力.因此本节主要给大家讲解一个开源的操作JavaBean的一个工具即BeanUt ...

  2. 工作总结 @{var sas = String.Format("{0:yyyy-MM-dd}", Model.DemandTime.GetValueOrDefault());}

      可空DateTime类型 无法Tostring 或者 格式化时间格式   需要转换 为DateTime Nullable<T>.GetValueOrDefault() 方法 返回对应的 ...

  3. Junit运行在Spring环境下

    @RunWith(SpringJUnit4ClassRunner.class)让测试运行于Spring测试环境 @ContextConfiguration 用来指定加载的Spring配置文件的位置,会 ...

  4. Netty的ByteBuf

    https://blog.csdn.net/thinking_fioa/article/details/80795673  netty的ByteBuf知识点

  5. linux性能不好怎么办?对着清单撸一遍

    性能不好怎么办?对着清单撸一遍 Brendan Gregg是Netflix的资深性能架构师,著名性能调优专家.著有<性能之巅:洞悉系统.企业与云计算>)一书,可以说是性能调优领域的集大成之 ...

  6. solr 简单搭建 数据库数据同步(待续)

    原来在别的公司负责过文档检索模块的维护(意思就是不是俺开发的啦). 所以就略微接触和研究了下文档检索. 文档检索事实上是全文检索.是通过一种技术把N多文档进行一定规律的分割归类,然后创建易于搜索的索引 ...

  7. Google 商店:您的应用静态链接到的 OpenSSL 版本有多个安全漏洞。建议您尽快更新 OpenSSL

    安全提醒 您的应用静态链接到的 OpenSSL 版本有多个安全漏洞.建议您尽快更新 OpenSSL. 在开头为 1.0.1h.1.0.0m和 0.9.8za的 OpenSSL 版本中这些漏洞已得到修复 ...

  8. apache官方中文hadoop说明文档地址

    http://hadoop.apache.org/docs/r1.0.4/cn/quickstart.html

  9. ERROR 1130 (HY000): Host '192.168.0.190' is not allowed to connect to this MySQL serv

    环境: CentOS6.2.MySQL5.1 问题描述: 在配置文件中将需要连接的MySQL的host设置为192.168.0.190(其实就是我自己的IP地址),然后运行自己的程序,结果返回MySQ ...

  10. windows7环境下使用pip安装MySQLdb

    1.首先,需要确定你已经安装了pip.在Python2.7的安装包中,easy_install.py和pip都是默认安装的.可以在Python的安装目录先确认,如果\Python27\Scripts里 ...