本文共 1141 字,大约阅读时间需要 3 分钟。
初始状态没有任何数字。
现在有3种操作,共m个, 操作1:add x,表示添加数字为x,如果系统内有一个与x相差≤k的数字,则忽略这次添加操作 操作2:del x,表示删除数字x,若存在多个与x相差≤k的数字,则全部删除,若没有数字x,则忽略该操作, 操作3:query x,判断是否存在一个数字与x的相差≤k。#includeusing namespace std;set aa;int main(){ ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int m,k; cin>>m>>k; string str; int x; for(int i=0; i >str; if(str[0]=='a') { cin>>x; if(aa.size()!=0) { set ::iterator iter=aa.lower_bound(x-k); if(*iter x+k) { aa.insert(x); } } else aa.insert(x); } else if(str[0]=='d') { cin>>x; set ::iterator iter=aa.lower_bound(x-k); stack bb; for(; iter!=aa.end()&&((*iter)<=x+k); iter++) { bb.push(*iter); } while(!bb.empty()) { aa.erase(bb.top()); bb.pop(); } } else { cin>>x; if(aa.size()==0) { cout<<"No"<
转载地址:http://oyhlz.baihongyu.com/