博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Codeforces Round #371 (Div. 2) C. Sonya and Queries
阅读量:6820 次
发布时间:2019-06-26

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

C. Sonya and Queries
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Today Sonya learned about long integers and invited all her friends to share the fun. Sonya has an initially empty multiset with integers. Friends give her t queries, each of one of the following type:

  1.  +  ai — add non-negative integer ai to the multiset. Note, that she has a multiset, thus there may be many occurrences of the same integer.
  2.  -  ai — delete a single occurrence of non-negative integer ai from the multiset. It's guaranteed, that there is at least one ai in the multiset.
  3. ? s — count the number of integers in the multiset (with repetitions) that match some pattern s consisting of 0 and 1. In the pattern, 0 stands for the even digits, while 1 stands for the odd. Integer x matches the pattern s, if the parity of the i-th from the right digit in decimal notation matches the i-th from the right digit of the pattern. If the pattern is shorter than this integer, it's supplemented with 0-s from the left. Similarly, if the integer is shorter than the pattern its decimal notation is supplemented with the 0-s from the left.

For example, if the pattern is s = 010, than integers 92, 2212, 50 and 414 match the pattern, while integers 3, 110, 25 and 1030 do not.

Input

The first line of the input contains an integer t (1 ≤ t ≤ 100 000) — the number of operation Sonya has to perform.

Next t lines provide the descriptions of the queries in order they appear in the input file. The i-th row starts with a character ci — the type of the corresponding operation. If ci is equal to '+' or '-' then it's followed by a space and an integer ai (0 ≤ ai < 1018) given without leading zeroes (unless it's 0). If ci equals '?' then it's followed by a space and a sequence of zeroes and onse, giving the pattern of length no more than 18.

It's guaranteed that there will be at least one query of type '?'.

It's guaranteed that any time some integer is removed from the multiset, there will be at least one occurrence of this integer in it.

Output

For each query of the third type print the number of integers matching the given pattern. Each integer is counted as many times, as it appears in the multiset at this moment of time.

Examples
Input
12 + 1 + 241 ? 1 + 361 - 241 ? 0101 + 101 ? 101 - 101 ? 101 + 4000 ? 0
Output
2 1 2 1 1
Input
4 + 200 + 200 - 200 ? 0
Output
1
Note

Consider the integers matching the patterns from the queries of the third type. Queries are numbered in the order they appear in the input.

  1. 1 and 241.
  2. 361.
  3. 101 and 361.
  4. 361.
  5. 4000.    
    /*给你一个容器你可以向里添加元素,也可以删除里面已有的元素询问:输入一个二进制数1表示奇数0表示偶数,返回对应的数的个数,所有询问都是从右边开始,位数不够用0补充字典树,插入01数,删除的地方只需要将对应字段末尾减1就可以*/#include 
    using namespace std;const int N = 5000000+10;struct Trie{ int ch[N][3]; int sz; int val[N]; void Init() { sz=1; memset(ch,0,sizeof ch); memset(val,0,sizeof val); } /* 0是偶数 1是奇数 */ void Insert(char *num,int op)//插异或 { //cout<<"num="<
    <
    =strlen(num);i--) { if(ch[u][0]==0)///无该儿子 ch[u][0]=sz++; u=ch[u][0]; } for(int i=0;i
    /*最后附上大神代码......大神的世界没有知识点只有乱搞*/#include 
    using namespace std;int cnt[1<<18];int main(){ int t; scanf("%d",&t); while(t--) { char ty[5],buf[25]; scanf("%s%s",ty,buf); int tmp=0; for(int i=0;buf[i];i++) tmp=tmp*2+(buf[i]-'0')%2; if(*ty=='?')printf("%d\n",cnt[tmp]); else cnt[tmp]+=(*ty=='+' ? 1 : -1); } return 0;}

     

转载于:https://www.cnblogs.com/wuwangchuxin0924/p/6031497.html

你可能感兴趣的文章
STL——queue
查看>>
说一下函数重载和覆盖的区别
查看>>
C++关键字--volatile
查看>>
MySQL学习【第十篇存储引擎实际应用】
查看>>
IIS 8.0 Using ASP.NET 3.5 and ASP.NET 4.5微软官方安装指导
查看>>
navicat for mysql下载地址
查看>>
OBject-c 输出时的占位符
查看>>
九宫格数独--回溯法
查看>>
要获得“机器学习或数据科学”的工作,到底选哪种编程语言更好?
查看>>
教程视频、项目源码、全部干货【微信小程序、React Native、Java、iOS、数据结构】...
查看>>
iOS 如何根据经纬度来定位位置
查看>>
删除难以删除的文件
查看>>
Windows下编译SDL
查看>>
pytorch梯度裁剪(Clipping Gradient):torch.nn.utils.clip_grad_norm
查看>>
Android--onMeasure()和onLayout()
查看>>
第一周 从C走进C++ 004 引用
查看>>
经典管理学定律5 - 羊群效应
查看>>
nginx在基于域名访问的时候是下载的界面
查看>>
树与二叉树
查看>>
[ 第二章] JavaScript 语法(五)循环语句
查看>>