CF713A.Sonya and Queries

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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 tt queries, each of one of the following type:

  1. ++ aia_{i} — add non-negative integer aia_{i} to the multiset. Note, that she has a multiset, thus there may be many occurrences of the same integer.
  2. - aia_{i} — delete a single occurrence of non-negative integer aia_{i} from the multiset. It's guaranteed, that there is at least one aia_{i} in the multiset.
  3. ?? ss — count the number of integers in the multiset (with repetitions) that match some pattern ss consisting of 00 and 11 . In the pattern, 00 stands for the even digits, while 11 stands for the odd. Integer xx matches the pattern ss , if the parity of the ii -th from the right digit in decimal notation matches the ii -th from the right digit of the pattern. If the pattern is shorter than this integer, it's supplemented with 00 -s from the left. Similarly, if the integer is shorter than the pattern its decimal notation is supplemented with the 00 -s from the left.

For example, if the pattern is s=010s=010 , than integers 9292 , 22122212 , 5050 and 414414 match the pattern, while integers 33 , 110110 , 2525 and 10301030 do not.
今天,索尼娅学习了长整数,并邀请她所有的朋友一起分享乐趣。索尼娅有一个包含整数的初始空多集合。朋友们给了她 t 个查询,每个查询都属于以下类型之一:

+  ai - 向多集合添加非负整数 ai 。请注意,她有一个多集合,因此同一个整数可能会出现很多次。
 -  ai - 从多集中删除一个出现过的非负整数 ai 。保证多集中至少有一个 ai 。
? s - 计算多集中匹配由 0 和 1 组成的模式 s 的整数(有重复)的个数。在该模式中, 0 代表偶数位,而 1 代表奇数位。如果整数 x 的十进制数字右起第 i 位的奇偶校验数与码型右起第 i 位的奇偶校验数一致,则与码型 s 匹配。如果码型短于这个整数,则从左边开始补充 0 -s。同样,如果整数比模式短,则其十进制符号从左边开始补充 0 -s。
例如,如果模式为 s = 010 ,则整数 92 、 2212 、 50 和 414 与模式匹配,而整数 3 、 110 、 25 和 1030 与模式不匹配。

输入格式

The first line of the input contains an integer tt ( 1<=t<=1000001<=t<=100000 ) — the number of operation Sonya has to perform.

Next tt lines provide the descriptions of the queries in order they appear in the input file. The ii -th row starts with a character cic_{i} — the type of the corresponding operation. If cic_{i} is equal to '+' or '-' then it's followed by a space and an integer aia_{i} ( 0<=ai<10180<=a_{i}<10^{18} ) given without leading zeroes (unless it's 0). If cic_{i} equals '?' then it's followed by a space and a sequence of zeroes and onse, giving the pattern of length no more than 1818 .

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.
输入
输入的第一行包含一个整数 t ( 1 ≤ t ≤ 100 000 ) - 索尼娅要执行的操作数。
接下来的 t 行按照输入文件中出现的顺序提供了查询描述。第 i 行以字符 ci - 对应操作的类型开头。如果 ci 等于"+"或"-",则后面跟一个空格和一个不带前导零的整数 ai(0ai<1018ai ( 0 ≤ ai < 10^{18} )(除非是0)。如果 ci 等于'?',那么后面就是一个空格和一连串的 0 和 onse,给出的模式长度不超过 18 。

可以保证至少有一个查询类型为'?' 。

每次从多集合中删除某个整数时,保证至少有一个整数出现在多集合中。

输出格式

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.
输出
对于第三种类型的每个查询,打印与给定模式匹配的整数个数。每个整数在此刻出现在多集中的次数相同。

每次从多集合中删除某个整数时,保证至少有一个整数出现在多集合中。

输入输出样例

  • 输入#1

    12
    + 1
    + 241
    ? 1
    + 361
    - 241
    ? 0101
    + 101
    ? 101
    - 101
    ? 101
    + 4000
    ? 0
    

    输出#1

    2
    1
    2
    1
    1
    
  • 输入#2

    4
    + 200
    + 200
    - 200
    ? 0
    

    输出#2

    1
    

说明/提示

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. 11 and 241241 .
  2. 361361 .
  3. 101101 and 361361 .
  4. 361361 .
  5. 40004000 .
    注意
    考虑与第三类查询中的模式匹配的整数。查询按在输入中出现的顺序编号。
    1 和 241 。
    361 。
    101 和 361 。
    361 。
    4000 。
首页