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 #371 (Div. 2) C. Sonya and Queries 水题

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

  2. Codeforces Round #371 (Div. 2) C. Sonya and Queries —— 二进制压缩

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

  3. Codeforces Round #371 (Div. 2) C. Sonya and Queries

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

  4. Codeforces Round #371 (Div. 1) C. Sonya and Problem Wihtout a Legend 贪心

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

  5. Codeforces Round #371 (Div. 2)E. Sonya and Problem Wihtout a Legend[DP 离散化 LIS相关]

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

  6. Codeforces Round #371 (Div. 1) C - Sonya and Problem Wihtout a Legend

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

  7. Codeforces Round #371 (Div. 1)

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

  8. 递推 Codeforces Round #186 (Div. 2) B. Ilya and Queries

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

  9. Codeforces Round #371 (Div. 2) 转换数字

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

随机推荐

  1. JavaScript学习笔记-用于模式匹配的String方法

    用于模式匹配的String方法:   String支持4种使用正则表达式的方法:           seach()用于检索,参数是一个正则表达式,返回第一个与之匹配的子串的位置,找不到则返回-1,如 ...

  2. tmtTable设计说明文档

    文件链接:tmt-table.js BOSS后台项目用到最多的就是列表页,所以把列表页做成通用组件,可以大大提高开发效率. 因为列表可能有不同的样式,所以在实例化组件时可以传值控制样式,用这种方式: ...

  3. Sharepoint学习笔记—习题系列--70-576习题解析 -(Q29-Q31)

    Question 29 You are designing a SharePoint 2010 intranet site at your company. The accounting depart ...

  4. JavaScript学习13 JavaScript中的继承

    JavaScript学习13 JavaScript中的继承 继承第一种方式:对象冒充 <script type="text/javascript"> //继承第一种方式 ...

  5. Android Studio git 版本回退到最新的版本

    1.场景 1.1 最新三次的提交 分别是:定义了一个变量k = 10 . 定义了一个变量 j = 6  . 定义了一个变量 i = 5 ; 本地仓库 和 远程仓库保持一致 1.2  我添加了一行代码 ...

  6. 功能源代码(扇形进度)及Delegate运用在开放事件中、UINavigationController的封装

    1:扇形进度视图及运用 首先先创建扇形的视图,传入进度值 #import <UIKit/UIKit.h> @interface LHProgressView : UIView @prope ...

  7. 【Android】保存Fragment切换状态

    前言 一般频繁切换Fragment会导致频繁的释放和创建,如果Fragment比较臃肿体验就非常不好了,这里分享一个方法. 声明 欢迎转载,但请保留文章原始出处:)  博客园:http://www.c ...

  8. HTTP和GET/POST请求(NSURLConnection)

    网络编程 网络编程是一种实时更新应用数据的常用手段 网络编程是开发优秀网络应用的前提和基础 网络基本概念 客户端(就是手机或者ipad等手持设备上面的APP) 服务器(远程服务器-本地服务器) 请求( ...

  9. BIEE建模参考规范

    BIEE建模参考规范 注:本文基于网上盛传的“BIEE建模黄金法则”,并做了更为细致的讲解,以及修改. 物理层 1.  在可能的情况下,配置你的连接池使用本地驱动来连接物理数据库.例如,使用OCI而不 ...

  10. MongoDB ServerStatus返回信息

    ServerStatus返回信息 ServerStatus返回mongodb中很多信息 http://docs.mongodb.org/manual/reference/command/serverS ...