博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
NC17508 指纹锁
阅读量:648 次
发布时间:2019-03-15

本文共 1141 字,大约阅读时间需要 3 分钟。

题目链接

题意

初始状态没有任何数字。

现在有3种操作,共m个,
操作1:add x,表示添加数字为x,如果系统内有一个与x相差≤k的数字,则忽略这次添加操作
操作2:del x,表示删除数字x,若存在多个与x相差≤k的数字,则全部删除,若没有数字x,则忽略该操作,
操作3:query x,判断是否存在一个数字与x的相差≤k。

思路

  • 使用map根据题意模拟即可,要使用快速的输入输出方式

参考代码

#include
using 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"<
::iterator iter=aa.lower_bound(x-k); if(*iter

转载地址:http://oyhlz.baihongyu.com/

你可能感兴趣的文章