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 with0-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串。从右到左对应了每个位置上的要求:0该位置为偶数。1该位置为奇数.

如果01串和要判断的数字不一样。谁短谁前面就补0;

我们不管谁短。直接在输入的数字前面补0至18位就好。

然后用字典树来操作。

插入数字的时候。不要具体记录这个数字是什么(没用!),只要知道这个数字是奇数还是偶数就行了嘛。所以93432你就记录11010.

不要被惯性思维影响!

直接记录数字会T!

然后字典树的域要记录以这个节点为终点的数字个数。

每次到这个节点累加这个就可以了。

【代码】

#include <cstdio>
#include <cstring> using namespace std; const int MAX_SIZE = 2000000; int t;
int tree[MAX_SIZE][2] = { 0 },totn = 0,ans = 0;
int e[MAX_SIZE] = { 0 }, stop[MAX_SIZE] = { 0 };
char op[5], dig[30]; void insert()
{
int temp = 0;
int len = 18;
for (int i = len-1; i >=0; i--)
{
int d = dig[i] - '0';
d = d % 2;//直接记录是奇数还是偶数就可以了。
if (tree[temp][d] == 0)
tree[temp][d] = ++totn;
temp = tree[temp][d];
stop[temp]++;
}
e[temp]++;
} void de_lete()
{
int temp = 0;
int len = 18;
for (int i = len-1; i >=0; i--)
{
int d = dig[i] - '0';
d = d % 2;
temp = tree[temp][d];
stop[temp]--;
}
e[temp]--;
} void dfs(int rt, int len) //用dfs来累加答案。
{
ans += e[rt];
if (len < 0)
return;
int d = dig[len] - '0';
if (tree[rt][d])
dfs(tree[rt][d], len - 1); } void get_ans()
{
int temp = 0;
int len = 18;
dfs(temp, len - 1);
} void input_data()
{
scanf("%d", &t);
char s1[30];
for (int i = 1; i <= t; i++)
{
scanf("%s%s", op, s1);
int len = strlen(s1);
for (int i = 0; i <= 18 - len - 1; i++)//补零
dig[i] = '0';
dig[18 - len] = '\0';
strcat(dig, s1);//最后dig记录的是补0后的字符
if (op[0] == '+')
insert();
else
if (op[0] == '-')
de_lete();
else
{
ans = 0;
get_ans();
printf("%d\n", ans);
}
}
} int main()
{
//freopen("F:\\rush.txt", "r", stdin);
input_data();
return 0;
}

【39.68%】【CF 714 C】Filya and Homework的更多相关文章

  1. [原]Water Water Search Problems&#39; Set~Orz【updating...】

    [HDU] [POJ] 作者:u011652573 发表于2014-4-30 10:39:04 原文链接 阅读:30 评论:0 查看评论

  2. jQuery 中的 39 个技巧【申明:来源于网络】

    jQuery 中的 39 个技巧[申明:来源于网络] 地址:http://blog.csdn.net/zhongqi2513/article/details/53704812?ref=myread

  3. 【codeforces】【比赛题解】#851 CF Round #432 (Div.2)

    cf真的难…… 点我浏览丧题. [A]Arpa和她对墨西哥人浪的研究 Arpa正在对墨西哥人浪进行研究. 有n个人站成一排,从1到n编号,他们从时刻0开始墨西哥人浪. 在时刻1,第一个人站起来.在时刻 ...

  4. 剑指Offer:数组中出现次数超过一半的数字【39】

    剑指Offer:数组中出现次数超过一半的数字[39] 题目描述 数组中有一个数字出现的次数超过数组长度的一半,请找出这个数字.例如,输入一个长度为9的数组{1,2,3,2,2,2,5,4,2}.由于这 ...

  5. poj 2411 Mondriaan&#39;s Dream 【dp】

    题目:id=2411" target="_blank">poj 2411 Mondriaan's Dream 题意:给出一个n*m的矩阵,让你用1*2的矩阵铺满,然 ...

  6. 【LeetCode-面试算法经典-Java实现】【118-Pascal&#39;s Triangle(帕斯卡三角形)】

    [118-Pascal's Triangle(帕斯卡三角形(杨辉三角))] [LeetCode-面试算法经典-Java实现][全部题目文件夹索引] 原题 Given numRows, generate ...

  7. HDU1164_Eddy&#39;s research I【Miller Rabin素数测试】【Pollar Rho整数分解】

    Eddy's research I Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others ...

  8. 【OCP、OCM、高可用等】小麦苗课堂网络班招生简章(从入门到专家)--课程大纲

    [OCP.OCM.高可用等]小麦苗课堂网络班招生简章(从入门到专家)--课程大纲 小麦苗信息 我的个人信息 网名:小麦苗 QQ:646634621 QQ群:618766405 我的博客:http:// ...

  9. 每日构建【Daily Build Using CruiseControl.NET and MSBuild】(转载)

    在上一篇项目 管理实践教程二.源代码控制[Source Control Using VisualSVN Server and TortoiseSVN]中 我们已经讲解了如何使用TortoiseSVN和 ...

随机推荐

  1. Leetcode784.Letter Case Permutation字母大小写全排列

    给定一个字符串S,通过将字符串S中的每个字母转变大小写,我们可以获得一个新的字符串.返回所有可能得到的字符串集合. 示例: 输入: S = "a1b2" 输出: ["a1 ...

  2. 通过反射 往泛型Integer的集合里添加String 类型的数据 Day25

    package com.sxt.method1; import java.lang.reflect.Method; /* * 需求:通过反射 往泛型Integer的集合里添加String 类型的数据 ...

  3. 【UML】之简单概括 标签: uml图形 2014-11-09 11:24 1130人阅读 评论(24) 收藏

    29号开始看UML的视频,由于之前看视频总是一拖拖上半个月,所以这次打算速战速决,而且UML视频的讲解和内容并不算多,也比较容易懂,到后期更是花了很多时间来举例子巩固各种图的画法,所以这次花了11天初 ...

  4. UVA_401:Palindromes

    AC:Time(29ms)     C++ 4.8.2 #include<stdio.h> #include<string.h> char * mirstr = "A ...

  5. C++结构体中的静态变量

    分享一个挺有意思的代码: #include <bits/stdc++.h> using namespace std; struct Point { static int cnt; Poin ...

  6. 实践分享:开始用Cordova+Ionic+AngularJS开发App

    http://www.cocoachina.com/webapp/20150707/12395.html 本文是一篇关于我本人在使用Cordova+Ionic以及AngularJS开发移动App的过程 ...

  7. qt开发ROS gui 遇到:global.h:1087:4: error: #error &quot;You must build your code with position independent code if Qt was built with -reduce-relocations. &quot......

    具体错误如下: 一共出现38个错误 这个错误是在导入cmakelists.txt时产生的,其实不是工程本身的问题,是因为我卸载ros,再重新安装ros的过程中把qtcreator的部分包给删除了,导致 ...

  8. 阿里云POLARDB如何助力轻松筹打造5亿用户信赖的大病筹款平台?

    轻松筹首创了“大病救助”模式,帮助了众多病患在第一时间解決了医疗资金等问题,为了从源头解决了医疗资金问题.而在轻松筹这样全球5.5亿用户信赖的大病筹款平台的背后,是日益增长的各种数据.面对这样数据量所 ...

  9. docker compose安装gitea

    docker-compose.yml version: "3.4" networks: gitea: external: false services: server: image ...

  10. day5-python之递归与二分法

    一.递归的定义 递归调用是函数嵌套调用的一种特殊形式,函数在调用时,直接或间接调用了自身,就是递归调用 二.递归分为两个阶段:递推,回溯 age(5) = age(4) + 2 age(4) = ag ...