http://hsacm.cn/JudgeOnline/problem.php?id=1443
这题直接用SET就可以做,但是有一个严重的问题就是超时。所以这个时候体现了lower_bound函数的重要性,
lower_bound(B)返回的是不小于B的第一个值得位置。原来SET也可以调用这个函数。
还有一个坑点是HSACM上不能不能用I64d.改成lld分分钟AC.
#include<iostream>
#include<cstdio>
#include<cmath>
#include<vector>
#include<cstring>
#include<algorithm>
#include<string>
#include<set>
#include<functional>
#include<numeric>
#include<sstream>
#include<stack>
#include<map>
#include<queue>
using namespace std;
int main()
{
long long n;
long long m=1;
while(cin >> n && n)
{
char s[100];
set<pair<long long,long long> > se;
set<pair<long long,long long> >::iterator ite;
printf("Case %d:\n",m++);
while(n--)
{
scanf("%s",s);
pair<long long,long long> p;
scanf("%lld%lld",&p.first,&p.second);
if(s[0]=='a')
se.insert(p);
else if(s[0]=='f')
{
ite = se.lower_bound(p);
for(;ite!=se.end();ite++)
{
if(ite->first>p.first&&ite->second>p.second)
{
printf("%lld %lld\n",ite->first,ite->second);
break;
}
}
if(!(ite!=se.end()))
printf("-1\n");
}
else if(s[0]=='r')
se.erase(p);
}
printf("\n");
se.clear();
}
return 0;
}