Codeforces Round #371 (Div. 2) C. Sonya and Queries[Map|二进制]

时间:2023-01-31 07:41:10
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, 0stands 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.

题意:插入删除数字 查询模式


一开始想了一个好像很厉害的做法,位向量树,实在调试不出来了

然后突然发现,数字是按十进制不是二进制

并且,数字和模式高位的0补位其实没什么影响,就是没有值,就是没有

所有把数字和模式都变成十进制或二进制01串然后用map或一个数组(2^18=262144)加减就行了

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <map>
using namespace std;
typedef long long ll;
const int N=;
inline ll read(){
ll x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
ll t,a;
char c[],s[];
//map<ll,int> mp;
int mp[N];
int main(int argc, const char * argv[]) {
t=read();
while(t--){
scanf("%s",c);a=read();
ll b=,k=;
while(a){
b+=a%*k;
a/=;
k*=;
}
if(c[]=='+') mp[b]++;
if(c[]=='-') mp[b]--;
if(c[]=='?') printf("%d\n",mp[b]);
}
return ;
}

Codeforces Round #371 (Div. 2) C. Sonya and Queries[Map|二进制]的更多相关文章

  1. Codeforces Round &num;371 &lpar;Div&period; 2&rpar; C&period; Sonya and Queries 水题

    C. Sonya and Queries 题目连接: http://codeforces.com/contest/714/problem/C Description Today Sonya learn ...

  2. Codeforces Round &num;371 &lpar;Div&period; 2&rpar; C&period; Sonya and Queries —— 二进制压缩

    题目链接:http://codeforces.com/contest/714/problem/C C. Sonya and Queries time limit per test 1 second m ...

  3. Codeforces Round &num;371 &lpar;Div&period; 2&rpar; C&period; Sonya and Queries

    题目链接 分析:01trie树,很容易就看出来了,也没什么好说的.WA了一发是因为没有看见如果数字位数大于01序列的时候01序列也要补全0.我没有晚上爬起来打,白天发现过的人极多. /******** ...

  4. Codeforces Round &num;371 &lpar;Div&period; 1&rpar; C&period; Sonya and Problem Wihtout a Legend 贪心

    C. Sonya and Problem Wihtout a Legend 题目连接: http://codeforces.com/contest/713/problem/C Description ...

  5. Codeforces Round &num;371 &lpar;Div&period; 2&rpar;E&period; Sonya and Problem Wihtout a Legend&lbrack;DP 离散化 LIS相关&rsqb;

    E. Sonya and Problem Wihtout a Legend time limit per test 5 seconds memory limit per test 256 megaby ...

  6. Codeforces Round &num;371 &lpar;Div&period; 1&rpar; C - Sonya and Problem Wihtout a Legend

    C - Sonya and Problem Wihtout a Legend 思路:感觉没有做过这种套路题完全不会啊.. 把严格单调递增转换成非严格单调递增,所有可能出现的数字就变成了原数组出现过的数 ...

  7. Codeforces Round &num;371 &lpar;Div&period; 1&rpar;

    A: 题目大意: 在一个multiset中要求支持3种操作: 1.增加一个数 2.删去一个数 3.给出一个01序列,问multiset中有多少这样的数,把它的十进制表示中的奇数改成1,偶数改成0后和给 ...

  8. 递推 Codeforces Round &num;186 &lpar;Div&period; 2&rpar; B&period; Ilya and Queries

    题目传送门 /* 递推:用cnt记录前缀值,查询区间时,两个区间相减 */ #include <cstdio> #include <algorithm> #include &l ...

  9. Codeforces Round &num;371 &lpar;Div&period; 2&rpar; 转换数字

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

随机推荐

  1. 【开源】SoDiaoEditor 可能是目前最好用的开源电子病历编辑器(B&sol;S架构)

    此刻我的内心是忐忑的,这个标题给了我很大的压力,虽然很久以前我就在github上搜索一圈了,也没发现有其他更好的开源电子病历编辑器,如各位亲发现有更好的,烦请知会我一声. 该编辑器其实已经憋了很久了, ...

  2. how to remove MouseListener &sol; ActionListener on a JTextField

    I have the following code adding an ActionListener to a JTextField: chatInput.addMouseListener(new j ...

  3. Delphi程序自删除的几种方法

    program Project1; uses SysUtils, windows; var f:textfile; a:string; begin a:=paramstr(); assignfile( ...

  4. 解除织梦dedeCMS标题&sol;关键词&sol; 简略标题长度限制听语音

    dedeCMS標題.關鍵詞和簡略標題長度有限制,展示不全. 三者均使用SQL修改dede_archives主表關鍵詞和簡略標題還需修改/dede/目錄中的: archives_add.php,     ...

  5. 彻底搞懂Scrapy的中间件(二)

    在上一篇文章中介绍了下载器中间件的一些简单应用,现在再来通过案例说说如何使用下载器中间件集成Selenium.重试和处理请求异常. 在中间件中集成Selenium 对于一些很麻烦的异步加载页面,手动寻 ...

  6. eclipse 中配置php的 XDebug调试

    1. 打开 eclipse for php IDE,window->preference->PHP->Debug 2. 配置phpserver 3. 我的已经增加好了,默认的应该有l ...

  7. netstat 常用参数总结

    netstat 是一个机器网络查看工具 . 网络连接有哪些参数? 

  8. Storm通信机制(了解)

    Worker间的通信:经常需要通过网络跨节点进行,Storm使用ZeroMQ或Netty(0.9以后默认使用)作为进程间通信的消息框架. Worker进程内部通信:不同worker的thread通信使 ...

  9. 2&period;4 C&plus;&plus;成员选择符

    参考:http://www.weixueyuan.net/view/6336.html 总结: 访问可以通过成员选择符“.”或指针操作符“->”来完成. 通过上一节的学习我们看到:通过对象可以访 ...

  10. Fiddler 抓包浅析

    Fiddler 工具浅析 Fiddler 是位于客户端和服务器端的 HTTP 代理,也是目前最常用的 HTTP 抓包工具之一.(Mac OS 建议采用 Charles) 它可以记录客户端和服务器之间的 ...