CF713A.Sonya and Queries
普及/提高-
通过率:0%
时间限制:1.00s
内存限制:256MB
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 t queries, each of one of the following type:
- + a__i — add non-negative integer a__i to the multiset. Note, that she has a multiset, thus there may be many occurrences of the same integer.
- - a__i — delete a single occurrence of non-negative integer a__i from the multiset. It's guaranteed, that there is at least one a__i in the multiset.
- ? 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.
今天,索尼娅学习了大整数,并邀请了她所有的朋友一起分享这份乐趣。索尼娅有一个初始为空的多重集(multiset),其中存放着若干整数。她的朋友们会向她提出 t 个查询,每个查询属于以下三种类型之一:
+ a_i—— 将一个非负整数 ai 加入该多重集中。注意:这是一个多重集,因此同一个整数可能出现多次;- a_i—— 从多重集中删除一个 ai 的出现(即仅删除一次)。题目保证此时多重集中至少存在一个 ai;? s—— 统计多重集中(含重复)有多少个整数 x 匹配给定的模式 s;该模式 s 仅由字符0和1构成。其中,0表示偶数数字,1表示奇数数字。整数 x 匹配模式 s,当且仅当:在十进制表示下,x 从右往左第 i 位数字的奇偶性,与模式 s 从右往左第 i 位字符所表示的奇偶性一致。若模式 s 的长度小于 x 的十进制位数,则 s 在左侧补0;类似地,若 x 的十进制位数小于 s 的长度,则 x 的十进制表示也在左侧补0。
例如,若模式为 s=010,则整数 92、2212、50 和 414 均匹配该模式;而整数 3、110、25 和 1030 则不匹配。
输入格式
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 c__i — the type of the corresponding operation. If c__i is equal to '+' or '-' then it's followed by a space and an integer a__i (0 ≤ a__i < 1018) given without leading zeroes (unless it's 0). If c__i 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.
输入的第一行包含一个整数 t(1≤t≤100000)—— 表示 Sonya 需要执行的操作次数。
接下来的 t 行按输入文件中出现的顺序给出各查询的描述。第 i 行以一个字符 ci 开头,表示对应操作的类型:若 ci 为 '+' 或 '-',则其后跟一个空格及一个整数 ai(0≤ai<1018),该整数不带前导零(除非它本身为 0);若 ci 为 '?',则其后跟一个空格及一个由 0 和 1 组成的字符串(即模式串),其长度不超过 18。
保证至少存在一个类型为 '?' 的查询。
保证在任意时刻,若某个整数从多重集(multiset)中被移除,则该整数在多重集中至少存在一次。
输出格式
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 and 241.
-
- 101 and 361.
-
-
考虑匹配第三类查询中模式的整数。查询按其在输入中出现的顺序编号。
- 1 和 241。
- 361。
- 101 和 361。
- 361。
- 4000。
输入解题思路,AI测评打分。不知道怎么写?