题目链接:http://codeforces.com/contest/714/problem/C

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.

题解: 

由于查询模式中只有01串(代表奇偶),所以输入的数字只需用01记录每一位奇偶性。故可以用二进制对数字进行压缩归类。由于1<<18=26214, 范围不是很大,所以可以用数组记录每个二进制数出现的个数,之后就可以直接修改,查询了。

代码如下:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<vector>
#include<map>
#include<string>
#include<set>
#define LL long long
#define MAX(a,b) (a>b?a:b)
#define MIN(a,b) (a<b?a:b)
#define INF 0x7fffffff
#define LNF ((1LL<<62)-1)
#define mod 1000000007
#define maxn 300000 using namespace std; LL p[maxn];
char ch, s[50]; int main()
{
int n,bin;
scanf("%d",&n);
for(int i = 0; i<n; i++)
{
getchar();
scanf("%c%s",&ch,s);
bin = 0;
for(int j = 0,len = strlen(s); j<len; j++)
{
bin <<= 1;
if((s[j]-'0')&1)
bin++;
} if(ch=='+')
p[bin]++;
else if(ch=='-')
p[bin]--;
else
printf("%lld\n",p[bin]);
}
}

Codeforces Round #371 (Div. 2) C. Sonya and Queries —— 二进制压缩的更多相关文章

  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[Map|二进制]

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

  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. HDU1506 Largest Rectangle in a Histogram (动规)

    Largest Rectangle in a Histogram Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 ...

  2. MySQL主从复制技术与读写分离技术amoeba应用

    MySQL主从复制技术与读写分离技术amoeba应用 前言:眼下在搭建一个人才站点,估计流量会非常大,须要用到分布式数据库技术,MySQL的主从复制+读写分离技术.读写分离技术有官方的MySQL-pr ...

  3. 用Visual C++ 2010 载入动态链接库三部曲(使用第三方库的一般方法)

    以下以载入编译好的ACE动态链接库为例说明:这里如果你已经设置了环境变量ACE_ROOT ACE在VS2010下高速配置载入动态链接库三部曲:(这里如果你的ACE文件夹为E:\ACE_wrappers ...

  4. Jenkins和Maven构建持续集成

    真是运维的福利,不用在敲Linux命令了 须要的工具:Linux或window.Jenkins.tomcat7.Jdk.maven.项目部署的war包 1.首先从Jenkins官网下载最新的Jenki ...

  5. 网络通讯框架MINA和XSCOCKET的简单比较

    http://www.blogjava.net/ghostdog/archive/2008/06/10/MinaVsXsocket.html实在无聊,考虑把当前应用的通讯模式由http移植为socke ...

  6. 关于Win8 用不了USB转串口驱动

    win8系统必需要关闭设备驱动自己主动更新,否则联网更新的驱动是用不了的.操作过程例如以下: 打开控制面板,搜索"设备".更改设备安装设置 watermark/2/text/aHR ...

  7. AngularJS 实现 双击排序

    关键代码:html <th class="col-md-3"><a href="" ng-click="desc('2',la=!l ...

  8. 模式识别之分类器knn---c语言实现带训练数据---反余弦匹配

    邻近算法   KNN算法的决策过程 k-Nearest Neighbor algorithm是K最邻近结点算法(k-Nearest Neighbor algorithm)的缩写形式,是电子信息分类器算 ...

  9. LookAround开元之旅

    http://blog.csdn.net/lancees/article/details/17696805

  10. codevs1032

    题目地址:http://codevs.cn/problem/1032/ 分析: 题目数据有错.这题过不了才正常. 我调了非常久可是就是有两个点过不去.于是我把数据下了下来,找到WA的第五个点和第七个点 ...