HDU3627 set+map
题意:添加 删除 查找第一个x y都比它大的值
#include <iostream> #include <algorithm> #include <cstring> #include <cmath> #include <queue> #include <vector> #include <cstdio> #include <set> #include <map> using namespace std; set<int>s; set<int>::iterator ss; map<int,int>y; map<int,set<int> >f; map<int,set<int> >::iterator ff; int main() { //freopen("in.txt","r",stdin); int n,cas=1; while(~scanf("%d",&n)&&n) { if(cas!=1) printf("\n"); s.clear(); y.clear(); f.clear(); char str[10]; int a,b; printf("Case %d:\n",cas++); while(n--) { scanf("%s%d%d",str,&a,&b); if(str[0]=='a') { if(y.find(b)==y.end()) y[b]=1; else y[b]++; if(s.find(a)==s.end()) s.insert(a); ff=f.find(a); if(ff==f.end()) f[a].insert(b); else { ss=ff->second.find(b); if(ss!=ff->second.end()) continue; ff->second.insert(b); } } else if(str[0]=='f') { if(y.upper_bound(b)==y.end()) { printf("-1\n"); continue; } int p=a; while(1) { if(s.empty()) { printf("-1\n"); break; } ss=s.upper_bound(p); if(ss==s.end()) { printf("-1\n"); break; } else { int temp=*ss; p=temp; if(f[temp].empty()) continue; ss=f[temp].upper_bound(b); if(ss==f[temp].end()) continue; else { printf("%d %d\n",temp,*ss); break; } } } } else if(str[0]=='r') { f[a].erase(b); if(f[a].empty()) s.erase(a); if(!--y[b]) y.erase(b); } } } return 0; }