题目链接: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. Android 动态生成对话框和EditText

    /** * (获取输入) */ private void showInputDialog() { ScrollView scrollview = getInitView() ; final Linea ...

  2. 【java】深入分析Java ClassLoader原理

    一.什么是ClassLoader? 大家都知道,当我们写好一个Java程序之后,不是管是CS还是BS应用,都是由若干个.class文件组织而成的一个完整的Java应用程序,当程序在运行时,即会调用该程 ...

  3. Jmeter Summariser report及其可视化

    Jmeter summariser report的设置在:bin/jmeter.properties #------------------------------------------------ ...

  4. 手机遥控器,3.5mm耳机接口红外遥控改造解析

    很多家电都用红外遥控,如电视机.机顶盒.空调.电风扇等.越来越多的遥控器反而给我们带来了更多的问题,有时找不到遥控器放哪儿了,或者混淆了都是麻烦,事实上对手机进行简单的改造,可以自制一个万能红外遥控器 ...

  5. vue2.0 自定义 图片上传(UpLoader)组件

    1.自定义组件 UpLoader.vue <!-- 上传图片 组件 --> <template> <div class="vue-uploader"& ...

  6. Git经常使用命令

    git --version 版本号号git help 帮助gitk 是个图形化的查看工具.gitk --all 所有分支历史-----------------------git pull 先拉git ...

  7. asp.net MVC通用分页组件 使用方便 通用性强

    asp.net MVC通用分页组件 使用方便 通用性强   该分页控件的显示逻辑: 1 当前页面反色突出显示,链接不可点击 2 第一页时首页链接不可点击 3 最后一页时尾页链接不可点击 4 当前页面左 ...

  8. session写入数据库

    <?php class session { private static $handle = null; private static $ip = null; private static $l ...

  9. kubernetes之初始容器(init container)

    系列目录 理解初始容器 一个pod里可以运行多个容器,它也可以运行一个或者多个初始容器,初始容器先于应用容器运行,除了以下两点外,初始容器和普通容器没有什么两样: 它们总是run to complet ...

  10. vue directive demo

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...